Hi Can anyone Please let me know can we use php inbuilt function inside a twig file.if not then why.
What is the way then to access php inbuilt function inside a twig file.
Because in a application in 100 of time we need to check many conditions basis of php inbuilt function.I have tried in_array() function to check multiple vaslue selected in a multiple dropdown list but i am getting error Is_array() not defined.
As @DonCallisto Said, There is some PHP equivalent function exists in twig not all. So you cant call a php function from twig template. You may have to use a existing equivalent or need to create one if not exists.
One of the main reason is SoC. Template is for presentation layer of your application. So twig made available tools(filter,functions, global variables) to do that.
Though you have date function in twig. its not the same date function you have in php. To achieve a similar functionality you may have to use same or different approach in twig then php. for instance you can achieve php's in_array functionality using the twig's Containment Operator
Now come to last part of your question:
What is the way then to access php inbuilt function inside a twig file?
I think you already know the short answer from @DonCallisto. You can create your own extension. And define what function you needed. Or if you are crazy enough to access all php builtin function from your template, you can use this Extension. It will allow you to call any php functions by prefixed with php_. for example if you like to call in_array function, then you can call like php_in_array() from your template.
Twig have some php builtin functions equivalent. For instance
in_array() php function is
in twig function. Check it out
If you don't find some builtin, you need to write your own twig exstension