0

In Drupal-specific Twig template I can get current path like

{% set pagePath = path('<current>') %}

But such a way doesn't contain query string e.g. ?param=value if the latter is present in the path

Is there a "built-in" way in Drupal-specific Twig to get full path including query string?

Under "built-in" I mean "without preprocessing it in a PHP code", e.g. in a module or in the themename.theme file with PHP code

Note on possible duplicates

I am not sure this is a duplicate of https://stackoverflow.com/a/20329384 as Drupal has its own specific Twig syntax - unfortunately that Symfony-specific option doesn't work here.

8
  • DarkBee, why do you shorten the title? It's a question specific to Drupal + Twig and not "how to get current path" in general Commented Oct 26, 2022 at 16:00
  • There is no need to put tags in the title Commented Oct 26, 2022 at 16:01
  • @DarkBee: I agree with the prevailing guidance on "detagging" titles, but "How in Drupal-specific Twig template to get current path with query string?" would not normally be considered taggy. An example of a taggy title would be "Drupal Twig How can I get current path with query string in a template?" Sometimes the tags are bracketed, sometimes they are not, but either way, they aren't very clear, and are trying to duplicate the tag system. Commented Oct 26, 2022 at 18:59
  • FWIW, I think my Meta post here is the current canonical advice on detagging titles. In other words, if a title can be (re)written so that key words are naturally-occurring words that make grammatical sense, those key words do not need removing. Commented Oct 26, 2022 at 19:00
  • The only "vanilla" way I see, is that you pass the request instance to template to fetch the querystring. e.g. path('<current>', request.query.all()) - Also keep in mind that there is a full SE dedicated to drupal. Maybe you will get an answer faster there Commented Oct 27, 2022 at 5:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.