Is it possible to pass variables into an included twig template, where the template name is a variable in itself?
{% include('MyMainBundle:MyEntity:' ~ entity.templateName) %}
works, but when I try to also pass a variable into this template, twig throws a syntax error.
{% include('MyMainBundle:MyEntity:' ~ entity.templateName, {'name' : myName} ) %}
I see what I was doing wrong. I had combined two different versions of include, one using {{ and the other using {% due to the symfony and twig docs showing different ways of including templates. This was as simple as removing the parenthesis from my initial code and inserting a with prior to defining the argument.
You can include a template like this per http://symfony.com/doc/current/book/templating.html#including-other-templates
{{ include('AcmeArticleBundle:Article:articleDetails.html.twig', {'article': article}) }}
Or like this per http://twig.sensiolabs.org/doc/tags/include.html
{% include 'template.html' with {'foo': 'bar'} %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With