Answers.Body: <p>Not particularly proud of this code, but if you want to do it from Twig, something like this:</p>
  
  <pre><code>{% set countryList = ['United Kingdom', 'United States'] %}
  
  {% for country in craft.commerce.countriesList() %}
      {% if country != 'United Kingdom' and country != 'United States' %}
          {% set countryList = countryList|merge([country]) %}
      {% endif %}
  {% endfor %}
  
  &lt;ul&gt;
      {% for country in countryList %}
          &lt;li&gt;{{ country }}&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-23T18:34:48.783Z
Answers.LastActivityDate: 2016-03-23T18:34:48.783Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>I needed to add the country values to the array so used <a href="https://craftcms.stackexchange.com/a/14293/4466">Brad's answer</a> to come up with the following:</p>
  
  <pre><code>{% set countryList = [{'77':'United Kingdom'},{'233':'United States'}] %}
  {% for key, country in craft.commerce.countriesList %}
    {% if country != 'United Kingdom' and country != 'United States' %}
      {% set key_string = key|json_encode() %}
      {% set countryList = countryList|merge([{(key_string):country}]) %}
    {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>The above builds the array of countries with their values. The below is the code to loop over the array and fill a <code>select</code> menu with their values.</p>
  
  <pre><code>&lt;select&gt;
    {% for country in countryList %}
      {% for key, option in country %}
        {% set optionValue = (model ? model.countryId : '') %}
        &lt;option value="{{ key }}" {% if key == optionValue %} selected{% endif %}&gt;{{ option }}&lt;/option&gt;
      {% endfor %}
    {% endfor %}
  &lt;/select&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-26T15:02:26.453Z
Answers.LastActivityDate: 2016-08-26T15:02:26.453Z
Answers.LastEditDate: 2017-04-13T12:51:00.303Z
Answers.UserDisplayName: Luke Pearce
Body: <p>Is there a way I can have the array from <code>craft.commerce.countriesList</code> automatically default to the country my store is in?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-23T17:25:45.177Z
Comments.Text: What do you mean automatically default?  `craft.commerce.countriesList` just returns an array of `id` => `name` values from the `craft_commerce_countries` table in the database. You can do whatever you want with it.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-23T17:57:46.887Z
Comments.Text: well, if I'm looping over them in a select list, I'd want the UK (and perhaps the US) to be at the top of that list, rather than Afghanistan.
Comments.UserDisplayName: Steven Grant
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-23T18:16:49.557Z
Comments.Text: I'm playing fake Luke Holder here, but I don't believe Commerce has a specific setting to specify what country your store is in.  Maybe you want to match it by currency (messy) or by the locale Craft is currently using (slightly less messy).
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-23T18:22:00.037Z
Comments.Text: You're entirely correct, I was confusing matters with default currency. I guess I'm looking for a way with Twig to have UK appear first in the loop.
Comments.UserDisplayName: Steven Grant
Tags: <templating><plugin-craftcommerce><ecommerce>
Title: Have the country in craft.commerce.countriesList default
ThreadText: # Have the country in craft.commerce.countriesList default
  
  (Asked by: username_0 on 2016-03-23)
  
  Is there a way I can have the array from `craft.commerce.countriesList` automatically default to the country my store is in?
  
  **Tags:** templating, plugin-craftcommerce, ecommerce
  
  > **Comments:**
  > **username_1**: What do you mean automatically default?  `craft.commerce.countriesList` just returns an array of `id` => `name` values from the `craft_commerce_countries` table in the database. You can do whatever you want with it.  
  > **username_0**: well, if I'm looping over them in a select list, I'd want the UK (and perhaps the US) to be at the top of that list, rather than Afghanistan.  
  > **username_1**: I'm playing fake username_2 Holder here, but I don't believe Commerce has a specific setting to specify what country your store is in.  Maybe you want to match it by currency (messy) or by the locale Craft is currently using (slightly less messy).  
  > **username_0**: You're entirely correct, I was confusing matters with default currency. I guess I'm looking for a way with Twig to have UK appear first in the loop.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2016-03-23. Score: 3
  
  Not particularly proud of this code, but if you want to do it from Twig, something like this:
  
  ```
  {% set countryList = ['United Kingdom', 'United States'] %}
  
  {% for country in craft.commerce.countriesList() %}
      {% if country != 'United Kingdom' and country != 'United States' %}
          {% set countryList = countryList|merge([country]) %}
      {% endif %}
  {% endfor %}
  
  <ul>
      {% for country in countryList %}
          <li>{{ country }}</li>
      {% endfor %}
  </ul>
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2016-08-26. Score: 3
  
  I needed to add the country values to the array so used [username_1's answer](https://craftcms.stackexchange.com/a/14293/4466) to come up with the following:
  
  ```
  {% set countryList = [{'77':'United Kingdom'},{'233':'United States'}] %}
  {% for key, country in craft.commerce.countriesList %}
    {% if country != 'United Kingdom' and country != 'United States' %}
      {% set key_string = key|json_encode() %}
      {% set countryList = countryList|merge([{(key_string):country}]) %}
    {% endif %}
  {% endfor %}
  
  ```
  
  The above builds the array of countries with their values. The below is the code to loop over the array and fill a `select` menu with their values.
  
  ```
  <select>
    {% for country in countryList %}
      {% for key, option in country %}
        {% set optionValue = (model ? model.countryId : '') %}
        <option value="{{ key }}" {% if key == optionValue %} selected{% endif %}>{{ option }}</option>
      {% endfor %}
    {% endfor %}
  </select>
  
  ```
  
  
  ---
  
  