Skip to content

Instantly share code, notes, and snippets.

@LittleCoding
Created September 27, 2016 13:37
Show Gist options
  • Save LittleCoding/482bbcffbaa2a1cfaa53c6bcf35273ba to your computer and use it in GitHub Desktop.
Save LittleCoding/482bbcffbaa2a1cfaa53c6bcf35273ba to your computer and use it in GitHub Desktop.
Current URL path via Twig in Drupal 8
{#
/**
* @file
* Get the current URL path via Drupal 8 route name and twig function.
*/
#}
<a href="{{ url('<current>') }}">Current page</a>
@christinef1126
Copy link

christinef1126 commented Jun 7, 2021

Ah, I believe I have found the solution:

{% set url = url('')['#markup'] %}{{ url|split('/')|last }}

Thanks, it works perfectly.

@Alimba86
Copy link

Alimba86 commented Mar 8, 2024

Nice, thanks for sharing!

@gitressa
Copy link

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