Bolt\Twig\Handler\HtmlHandler::twig PHP Method

twig() public method

Note: this is partially duplicating the template_from_string functionality: http://twig.sensiolabs.org/doc/functions/template_from_string.html We can't use that functionality though, since it requires the Twig_Extension_StringLoader() extension. If we would use that, when instantiating Twig, it screws up the rendering: Every template that has a filename that doesn't exist will be rendered as literal string. This _really_ messes up the 'cascading rendering' of our theme templates.
public twig ( $snippet, array $extravars = [] ) : string
$snippet
$extravars array
return string Twig output
    public function twig($snippet, $extravars = [])
    {
        return $this->app['safe_render']->render($snippet, $extravars)->getContent();
    }

Usage Example

Beispiel #1
0
 public function testTwig()
 {
     $app = $this->getApp();
     $handler = new HtmlHandler($app);
     $result = $handler->twig("{{ 'koala'|capitalize }}");
     $this->assertSame('Koala', $result);
 }