Link to a node in twig [drupal 8]

Twig is the theme engine in drupal 8 sites. This snippet how to link to nodes correctly, without using preprocess functions to do it.

<a class="button" href="{{ path('entity.node.canonical', {'node': 23}) }}">{{ 'Newsletter'|t }}</a>
// This links correctly to /node/23 and will end up showing the alias f.e. /en/newsletter

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!