I want to use a Twig variable in a include line, but it isn't working:{% include 'folder/{{ component }}.twig' %}
I get the error:
Unable to find template "folder/{{ component }}.twig"
Can anyone help me out?
Thanks!
Using the Manage administrative menu, navigate to Configuration > Development > Devel settings (admin/config/development/devel) and under the heading, Variables Dumper, select Kint, then Save configuration. Like the dump function, kint() will not display any output unless debugging is enabled.
This can be accomplished by creating an array of the entry years. Inside the loop that's building the array, a conditional checks if the year already exists in the array... if the year exists, a variable is set to TRUE which you can use in your conditional later down on the page. Save this answer.
If you are using Twig in another project, you can set your globals directly in the environment: $twig = new Twig_Environment($loader); $twig->addGlobal('myStuff', $someVariable); And then use {{ myStuff }} anywhere in your application.
Blocks are used for inheritance and act as placeholders and replacements at the same time. They are documented in detail in the documentation for the extends tag. Block names must consist of alphanumeric characters, and underscores. The first char can't be a digit and dashes are not permitted.
I just found the answer here: https://groups.google.com/forum/#!topic/twig-users/zfnxC16gHx0
The correct syntax is:
{% include 'folder/' ~ component ~ '.twig' %}
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