0

I have a drop down select that I am populating with sites. I've added a lightswitch field (handle 'showInDropDown') to the global set 'siteInfo' with the hope of getting the lightswitch value per site in the loop below.

{% for siteId in currentSite.group.sites %}
    {% set setForSiteId = craft.app.getGlobals().getSetByHandle('siteInfo', SiteId =5) %}
    {{ setForSiteId.showInDropdown }}
{% endfor %}

The lightswitch field is set to translate per site. setForSiteId is always coming back null:

Impossible to access an attribute ("showInDropdown") on a null variable.

I am not sure if I am missing something. Is there another way to access global variables/values per site?

1 Answer 1

0

Finally solved with the following code:

    <select  class="form-control " name="sites" id="company-select">
    <option value="" class="small text-muted">Please select your company</option>
    {% for site in allSites %}
        {% set siteId = site.id %}
        {% set groupId = site.getGroup().id %}
        {% if groupId == '5' %}
            {% set setForSiteId = craft.app.getGlobals().getSetByHandle('siteInfo', siteId) %}
            {% if setForSiteId.showInDropdown == '1' %}
            <option value="{{baseUrl ~ '/' ~ site.handle }}">{{site.name}}</option>
                {% endif %}
        {% endif %}
    {% endfor %}
    </select>

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.