Reputation: 62
Hi everyone and sorry for my english,
I have a service who generates some html code which is passed to a twig template. I had to use the raw filter to show the code, but in that code I call a twig function.
This is the code stored in a var which is passed to the template by the controller.
'<li class="active" ><a href="{{ path(\'help\') }}">Help</a></li>'
The resulting html code is the same, so {{ path('help') }}
is not called.
Is there any filter to show the html code and call the functions?
Thanks
Upvotes: 0
Views: 1951
Reputation: 1327
In your code, you are using {{path('help')}} for the hyperlink. Instead of using the twig path function, include the original Url in the code that is sent from the service. In the service. use
'<li class="active" ><a href="'.$this->container->get('router')->generate('help').'">Help</a></li>'
Upvotes: 0
Reputation: 291
You should render your variable using the {% include(template_from_string(your_var)) %}
twig block.
See the answer of Render content from string/database and generate links with twig for more info.
Upvotes: 0
Reputation: 12725
I answered this before here: Twig: prevent parsing of client-side templates
{% raw %} deprecated
{% verbatim %}
<ul>
{% for item in seq %}
<li>{{ item }}</li>
{% endfor %}
</ul>
{% endverbatim %}
Upvotes: 0