Is it possible or not to use the built-in php function in Twig?

I am new to symfony. How can I use the built-in php function in a branch template?

For example, I want to use a function chrin a loop as follows:

{% for directory in directories %}
    chr(loop.index)
{% endfor %}
+5
source share
2 answers

Twig allows you to add functions and filters . There are several examples in the documentation .

For instance,

+8
source

No, you cannot directly use PHP in Twig.

There are several options:

Use PHP as a template engine

PHP . , PHP , PHP. . doc , .

Twig

Twig. AcmeTwigBundle, Twig. . doc , Symfony.

Twig 1.12 (Symfony2.2 ), , PHP :

new Twig_SimpleFilter('rot13', 'str_rot13');

rot13 Twig, str_rot13 PHP.

+3

All Articles