Closed jimblue closed 7 years ago
I've try to adapt the template to make this working but I'm not sure what is base_url_simple
for?
There is no documentation about this variable.
Anyway here is what I've write:
{% set langobj = grav['language'] %}
{% for key in langswitcher.languages %}
{% if key == langswitcher.current %}
{% set lang_url = page.url(true) %}
{% else %}
{% set lang_url = base_url_absolute ~ langobj.getLanguageURLPrefix(key)~langswitcher.page_route ?: '/' %}
{% endif %}
<link rel="alternate" hreflang="{{ key }}" href="{{ lang_url ~ uri.params }}" />
{% endfor %}
It could be the default template, what do you think?
In fact my solution is not working because base_url_absolute
returns the lang in the string too and that break the correct markup.
I've tried so many solution without success... 😞
As written in Slack, use base_url_simple
instead. That won't contain the lang string
tks @flaviocopes
Hey @flaviocopes !
I've just look at your solution but I notice that base_url_simple
is already what langswitcher.hreflang.html.twig
use.
And this doesn't give an absolute URL but a relative.
Hey,
First thanks for this nice plugin.
I just have a question about
langswitcher.hreflang.html.twig
. Why it returns a relative url?From what I've read the best practice is to use an absolute url like for
link rel="canonical"
.