3

How would I get the global variables associated to other sites?

For example, in an instance where I have three websites under the group languages for the English, Spanish, and French versions. I have specified companyInformation globals that contain: phone, address, and logo.

From a template I would like: - Loop through all sites under the group languages - Get companyInformation global values for each of the sites

Thanks in advance

1 Answer 1

3

The function is

public function getSetByHandle(string $globalSetHandle, int $siteId = null)

Thus you can grab all the siteIds you want and loop through them

{% for siteId in sites %}
    {% set setForSiteId = craft.app.getGlobals().getSetByHandle('handle', siteId) %} 
{% endfor %} 
1
  • Thanks Robin! Just for clarity purposes: We'd grab all sites with: {% set sites = craft.app.sites.getAllSites() %} And then use the loop you provided as follows: ```` {% for site in sites %} {% set siteGlobals = craft.app.getGlobals().getSetByHandle('myGlobalsHandle', site.id) %} {% endfor %} ````
    – cballenar
    Commented Jun 1, 2018 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.