Answer the question
In order to leave comments, you need to log in
How to add custom twig tag?
Good day.
How to add custom twig tag?
There are standard {{ - }} and {% - %}, but is it possible to add your own, like {dev - dev}?
Or how to do the following:
There is a tag, for example - {{ dev.XXX }} - instead of XXX - methods of a certain php class that return some data.
You can add each one separately, but in a bastard :) Is
it possible somehow automatically? So that all class methods are accessible by such an appeal
Answer the question
In order to leave comments, you need to log in
https : //symfony.com/doc/current/templating/global_... it
is
for symfony, but the essence is the
same
namespace App\Service;
class TwigGlobals
{
public function getInfo()
{
return [
'var_one' => 1,
'var_two' => 2,
];
}
}
{% block a %}
{{ getMainInfo().var_one }}
{% endblock %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question