0

I am calling a function in my controller file from my twig file, like I set my code as:

{% if myFunction('param1', 'param2') %}
    {{ 'do something' }}
{% endif %

}

But it giving this error.

Error :

Fatal error: Uncaught Twig_Error_Syntax: Unknown "myFunction" function in...

user3837868
  • 917
  • 1
  • 12
  • 24

1 Answers1

0

Its not possible to access any PHP function inside Twig directly.

You should use the function to set a variable in your controller and then test the truth of that variable in Twig.

Or see this: Call PHP function from Twig template

Paul Feakins
  • 719
  • 5
  • 7