Create necessary 'hreflang' link statements in head

35 views
Skip to first unread message

Ryan O'Dell

unread,
Sep 13, 2023, 11:38:06 AM9/13/23
to dotCMS User Group
Hi,

I'm looking to add alternate language link statements in the head section of the page and update the sitemap with the corresponding alternate language links.

e.g. <link rel="alternate" hreflang="en" href="https://en.example.com/page.html" />

Given a page load, in Velocity what would I use to check if there is a corresponding page for the same page identifier (assuming that's correct)?

I was going to use the following as it's performant: $dotcontent.find(..page identifier...)

However, I'm not sure if I can check the alternate language.

What would be the right way to detect this?

For the Sitemap I can probably handle that already.

Thank you,
Ryan

Ryan O'Dell

unread,
Oct 6, 2023, 1:18:45 PM10/6/23
to dotCMS User Group
For reference, we solved this by creating a VTL helper (Java plugin) to make use of the "ContentletAPI" and "findContentletForLanguage()" method.

We run some checks against the current page request and which language was requested vs which language the current page is, and then we use the above "findContentletForLanguage()" method to see if there is a corresponding version of the page for the alternate language.

If there is a match, we then output the necessary link statement in the head section of the page.

We already had a VTL helper (Java plugin), which meant it was easy enough to extend it's list of functionality.

Regards,
Ryan

Reply all
Reply to author
Forward
0 new messages