0

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

Javi
  • 62
  • 9
  • Your service should probably be a twig extension which you then call from inside of your template. – Cerad Sep 24 '13 at 11:40

3 Answers3

0

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 %}
Community
  • 1
  • 1
Farid Movsumov
  • 12,350
  • 8
  • 71
  • 97
0

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.

Community
  • 1
  • 1
bjuice
  • 291
  • 1
  • 8
0

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>'
Praveesh
  • 1,257
  • 1
  • 10
  • 23
  • That's exactly what I've done, I included the container as argument of my service and it generates all the href using the router component. Thanks for your help – Javi Sep 25 '13 at 13:25