James Monger
James Monger

Reputation: 10665

Using a Twig variable inside the 'use' tag

I want to dynamically use a Twig template, but for some reason I can't get it to work.

When I add this line, my page crashes:

{% use current_page %}

current_page is set to "birthday.twig", which exists.

Upvotes: 0

Views: 338

Answers (1)

andy
andy

Reputation: 2002

As the Twig documentation states:

Because use statements are resolved independently of the context passed to the template, the template reference cannot be an expression.

So unfortunately it is not possible to have a variable {% use xyz %} statement.

However, you can include using a variable. See http://twig.sensiolabs.org/doc/recipes.html

Upvotes: 1

Related Questions