June 11, 2020

Twig Function Cheatsheet

Drupal 8
Twig

Functions in Twig Templates Documentation

url()

{{ url('user.login') }}
{{ url('user.pass') }}
{{ url('user.register') }}
{{ url('user.register', { 'destination': '<some-route>' }) }}
{{ url('entity.user.canonical') }}
{{ url('<current>') }}
{{ url('<front>') }}

path()

{{ path('view.frontpage.page_1') }}
{{ path('entity.user.canonical', {'user': user.id}) }}
{{ path('entity.node.canonical', {'node': node.id}) }}
{{ path('node.add', {'node_type' : '<node_type>'}) }}