<p>Finally solved with the following code:</p>
<pre><code>    &lt;select  class=&quot;form-control &quot; name=&quot;sites&quot; id=&quot;company-select&quot;&gt;
    &lt;option value=&quot;&quot; class=&quot;small text-muted&quot;&gt;Please select your company&lt;/option&gt;
    {% 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' %}
            &lt;option value=&quot;{{baseUrl ~ '/' ~ site.handle }}&quot;&gt;{{site.name}}&lt;/option&gt;
                {% endif %}
        {% endif %}
    {% endfor %}
    &lt;/select&gt;
</code></pre>

CC BY-SA 4.0
2020-06-30T09:24:52.670Z
2020-06-30T09:24:52.670Z
joomkit
<p>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.</p>
<pre><code>{% for siteId in currentSite.group.sites %}
    {% set setForSiteId = craft.app.getGlobals().getSetByHandle('siteInfo', SiteId =5) %}
    {{ setForSiteId.showInDropdown }}
{% endfor %}
</code></pre>
<p>The lightswitch field is set to translate per site.
setForSiteId is always coming back null:</p>
<pre><code>Impossible to access an attribute (&quot;showInDropdown&quot;) on a null variable.
</code></pre>
<p>I am not sure if I am missing something. Is there another way to access global variables/values per site?</p>

<multi-site><globals>
Accessing global field values in site loop
# Accessing global field values in site loop

(Asked by: username_0 on 2020-06-24)

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?

**Tags:** multi-site, globals


---

## 1 answers

### Answer by username_0 on 2020-06-30. Score: 0 | Accepted answer

Finally solved with the following code:
    
    Please select your company
    {% 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' %}
            {{site.name}}
                {% endif %}
        {% endif %}
    {% endfor %}


---

