Call static methods from Twig template #3794
Answered
by
GromNaN
jdescelliers
asked this question in
Q&A
-
I'm trying to call a static method from a Twig template and It cannot be done easily. The main logic behind this is that 'pure' PHP classes are easier to test than Twig templates. Is there any way to beautifully call a static method from Twig or any plans to implement this feature? |
Beta Was this translation helpful? Give feedback.
Answered by
GromNaN
Dec 26, 2022
Replies: 1 comment
-
You can create an extension: https://symfony.com/doc/current/templating/twig_extension.html Or pass an object to global variables and call the method on this object. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
fabpot
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can create an extension: https://symfony.com/doc/current/templating/twig_extension.html
Or pass an object to global variables and call the method on this object.