Passing variable into included twig template that has variable in template name

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'} %}

Leave a Comment