I was working on issue queue of views extras module and came across a requirement: Add twig support: https://www.drupal.org/project/views_extras/issues/2948514. For a moment I was helpless, I mean I always had the requirement to use PHP function in twig but never thought in the reverse direction and to resolve that issue I need to know how we can support twig variables in PHP.
Now, this was interesting, so I began my search with finding out how Drupal handles output using twig how it replaces variables and all. I went into the code to find that but soon I changed my mind and found the solution another way.
Problem in brief: how "{{ user.getDisplayName() }}" can produce desired output as twig does and support similar stuff in PHP.
So, scratch your head and try to find a solution, let me see where you guys end up.
Solution :
To support the use of Twig syntax in PHP we can make use of inline_template render element introduced by Drupal
Reference: New inline_template render element for HTML code in PHP
Comments