0

I write a code generator in Symfony2 with twig.

My problem is: I want to create a twig template with a twig template.

For a better understanding here an example: I have a twig file that is a template for a PHP Page - so if i run it it generates me PHP code from that twig template. (ex. a Controller for CRUD)

Now I want to generate the view template - but how can i tell twig to use the commands I need for generation and let the dynamic parts for the template as is?

Can I change how the tags are formed? Can I change {{ varname }} in [[ varname ]] ?

THX for your help

Wollhaar
  • 182
  • 3
  • 22

2 Answers2

3

Of course you can!, take the Sensio CRUD generator as an example:

To prevent the rendering of some parts you can:

You might find the same issue working with AngularJS in Twig templates:

Community
  • 1
  • 1
coma
  • 16,429
  • 4
  • 51
  • 76
0

I think you are looking for the {% verbatim %} tag.

Verbatim let you write Twig code without interpretation, for example:

{% verbatim %}
  {% for key, value in array %}
    {{ value }}
  {% endfor %}
{% endverbatim %}

Will literally output:

  {% for key, value in array %}
    {{ value }}
  {% endfor %}
Alain Tiemblo
  • 36,099
  • 17
  • 121
  • 153