My website (drupal 8) was first in one language. Now I switched to multi langual.

Most of the settings i did find (translate content, webforms, strings,...).

But at the moment stuck on the hard coded links I use in the template (theming).

So I'm looking for the best way to let my hard coded links work for more languages.

At this moment this is what i got (and ofcourse this is not working well):

<h4><a href="/node/100">{{ 'DIENSTEN ON SITE'|t }}</a></h4>

This link doesn't bring the visitor to the correct link (en/ or fr/ is missing). Translate on the string works already :).

My current settings for detections are visible in the image: So first selection is on url/prefix

Thanks for reading!


2 Answers 2


For translated links you can use the path function

<a href="{{ path('entity.node.canonical', {'node': '100'}) }}"> {{ 'DIENSTEN ON SITE'|t }}</a>

Use a route name and parameters to generate the url. In Twig for example with path():

{# Link to node page. #}
<a href="{{ path('entity.node.canonical', {'node': node.id}) }}">{{ 'View node page'|t }}</a>

Then outbound path processing can apply the configured language detection methods.

  • Thanks. But where should i fill in the node ID? I try this <h4><a href="{{ path('entity.node.canonical', {'/node/100': node.id}) }}">{{ 'DIENSTEN ON SITE'|t }}</a></h4> ... But this broke the site.. :) Commented Feb 26, 2019 at 19:53
  • Don't change 'node', this is the required parameter name. Put the node ID after the colon (replace node.id). You might want to enable error reporting (/admin/config/development/logging) so that you see what breaks your site.
    – 4uk4
    Commented Feb 26, 2019 at 20:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.