I can't work out how to output <link rel="alternate"> for each language variation?
Is there any easy way to do this please?
Many thanks!
I can't work out how to output <link rel="alternate"> for each language variation?
Is there any easy way to do this please?
Many thanks!
If you're looking to get the locale code for each site's language globally, it'd be something like this:
{% for locale in craft.i18n.getSiteLocales() %}
{{ locale }}
{% endfor %}
If you're in the context of an entry, and you want to get the full URL and locale code for each site that entry is enabled it, it'd be similar to the answer here: https://craftcms.stackexchange.com/a/23751/57
{# Grab the entry #}
{% set entry = craft.entries.id(2).one() %}
{# loop through all of the supported sites for the entry #}
{% for siteInGroup in entry.getSupportedSites() %}
{% set site = craft.app.sites.getSiteById(siteInGroup['siteId']) %}
{# Grab the entry for the given site #}
{% set entryForSite = craft.entries.id(entry.id).siteId(site.id).one() %}
{# output the site-specific entry info #}
<link rel="alternate" href="{{ entryForSite.url }}" hreflang="{{ site.language }}">{{ entryForSite.title }}</link>
{% endfor %}