Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-30T09:24:52.670Z
Answers.LastActivityDate: 2020-06-30T09:24:52.670Z
Answers.UserDisplayName: joomkit
Body: <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>
  
Tags: <multi-site><globals>
Title: Accessing global field values in site loop
ThreadText: # 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:
  
  ```
      <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>
  
  ```
  
  
  ---
  
  