0

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!

Kristof

2 Answers 2

1

For translated links you can use the path function

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

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.

2
  • 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. Commented Feb 26, 2019 at 20:03

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.