In Symfony2, I created a simple action:
public function testAction()
{
return $this->render('TestBundle::test.html.twig', array(
'testBool' => true,
'testTplPath' => 'TestBundle::base.html.twig'
));
}
base.html.twig:
<html><body>{% block content %}{% endblock %}</body></html>
And now I have a problem with the tag extends in test.html.twig my template, if I use a simple string in the tag as follows: {% extends 'TestBundle::base.html.twig' %}everything is working fine, but it is not working properly {% extends testTplPath %}. The second example is mistake Variable "testTplPath" does not exist in TestBundle::test.html.twig at line 1.
This works great: {% extends testBool ? 'TestBundle::base.html.twig' : 'blah' %}
This throws an exception: {% extends testBool ? testTplPath : 'blah' %}- Variable "testBool" does not exist in TestBundle::test.html.twig at line 1(note that Twig throws this exception during a variable testBool- why ?!)
According to the TWIG documentation, all abowe examples should work, and I don't know what I did wrong.
I have done many tests, and I can’t determine any pattern when variables see excerpts and when not.
Twig v1.16.0 Symfony 2.5.4
: , , testTplPath , , Variable "[first var in expression]" does not exist, : Unable to find template "TestBundle::SomeInvalidTemplate.html.twig".
user1952959