0

I want get the pathInof in my template twig : enter image description here

How i can reach pathInfo please in my template ?

1

The screenshot is a render element of a link which gets printed in the template completely. What you find inside is for internal usage and is most times protected anyway.

To get this request parameter in your template build your own variable in preprocess:

$variables['path_info'] = \Drupal::request()->getPathInfo();

You might also need to add a cache context if your template depends on this information:

$variables['#cache']['contexts'][] = 'url.path';

Then print it in Twig:

{{ path_info }}

This is the general approach. In this specific case if you are interested in the current path (including the base path) then you could simply use a Twig function:

{{ path('<current>') }}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.