Bolt\Legacy\Content::preParse PHP Method

preParse() public method

If passed snippet contains Twig tags, parse the string as Twig, and return the results.
public preParse ( string $snippet, boolean $allowtwig ) : string
$snippet string
$allowtwig boolean
return string
    public function preParse($snippet, $allowtwig)
    {
        // Quickly verify that we actually need to parse the snippet!
        if (!$allowtwig || !preg_match('/[{][{%#]/', $snippet)) {
            return $snippet;
        }
        // Don't parse Twig for live editor.
        $request = $this->app['request_stack']->getCurrentRequest();
        if ($request && $request->request->getBoolean('_live-editor-preview')) {
            return $snippet;
        }
        $snippet = html_entity_decode($snippet, ENT_QUOTES, 'UTF-8');
        try {
            return $this->app['safe_render']->render($snippet, $this->getTemplateContext());
        } catch (\Twig_Error $e) {
            $message = sprintf('Rendering a record Twig snippet failed: %s', $e->getRawMessage());
            $this->app['logger.system']->critical($message, ['event' => 'exception', 'exception' => $e]);
            return $message;
        }
    }