TransWikia.com

How to directly access translated variables by language

Craft CMS Asked by Stabilimenta on June 17, 2021

I have a localized, two language site (en and fr) that I have a translated global variable set for. My question is: is there a way on a Craft 3 template to directly access a translation of a variable that isn’t the same as the currentSite language. Specifically, I’d like to show both translations of the same variable on one page.

I am getting the variable with this currently: siteOwnerInfo.siteOwner

One Answer

Take a look at the Craft docs page for "Globals" under Querying Globals.

You can pass a site ID number to an element query to get globals from another site/language. For example, if your French site id number is 2, you could do this:

{% set siteOwnerInfoFrench = craft.globalSets()
  .handle('siteOwnerInfo')
  .siteId(2).one() %}

{{ siteOwnerInfoFrench.siteOwner }}

Correct answer by Alex Roper on June 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP