Created
September 27, 2016 13:37
-
-
Save LittleCoding/482bbcffbaa2a1cfaa53c6bcf35273ba to your computer and use it in GitHub Desktop.
Current URL path via Twig in Drupal 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
/** | |
* @file | |
* Get the current URL path via Drupal 8 route name and twig function. | |
*/ | |
#} | |
<a href="{{ url('<current>') }}">Current page</a> |
Ah, I believe I have found the solution:
{% set url = url('')['#markup'] %}{{ url|split('/')|last }}
Ah, I believe I have found the solution:
{% set url = url('')['#markup'] %}{{ url|split('/')|last }}
Thanks, it works perfectly.
Nice, thanks for sharing!
Thanks, works well! For more URL path Twig tips in Drupal, see Functions in Twig templates.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works great, but what if I only need a specific parameter from the URL? For example, I want to style a portion of the Commerce checkout process if the user is on the Review page (mysite.com/checkout/388/review). How can I get just that final parameter (review)? When I use this code (
If I can get just "review" as that part of the class, I will be able to use CSS to style that area of the order review page.