Answers.Body: <p>If you look at <a href="https://github.com/pixelandtonic/Craft-Release/blob/master/app/framework/i18n/data/en_gb.php" rel="nofollow noreferrer">the data file for a locale in Yii</a> you can see that the territories property includes regions and continents as you've found. These all have keys with numeric values, whereas countries have two character keys. Using this knowledge, you can loop over the keys and values of the territories array as you are doing, but only output those with two character keys. You'll also probably want to omit the <code>Unknown Region</code> value which has a key of <code>zz</code>.</p>
  
  <p>Untested, but this should work:</p>
  
  <pre><code>&lt;select name="country" required&gt;
      {% for key, value in craft.i18n.getLocaleData().getAllTerritories() %}
          {% if (key matches '/[a-z][a-z]/') and (key != 'zz') %}
              &lt;option&gt;{{ value }}&lt;/option&gt;
          {% endif %}
      {% endfor %}
  &lt;/select&gt;
  </code></pre>
  
  <hr>
  
  <p>EDIT</p>
  
  <p>OK, so my original idea doesn't work as <code>craft.i18n.getLocaleData().getAllTerritories()</code> doesn't preserve the territory array keys from the Yii i18n data files.</p>
  
  <p>I'm not sure you can do what you want to do natively in Craft, but it looks like <a href="https://github.com/johndwells/craft.territories" rel="nofollow noreferrer">John D. Wells' Territories fieldtype plugin</a> may provide what you need. You don't need to use the fieldtype as there is an undocumented Twig variable provided that gives you an array of localised territory names, excluding the regions. Try this:</p>
  
  <pre><code>&lt;select name="country" required&gt;
      {% for country in craft.territories.getTerritories() %}
          &lt;option&gt;{{ country }}&lt;/option&gt;
      {% endfor %}
  &lt;/select&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-06T15:51:36.410Z
Answers.Text: Thanks Steve. I get a preg_match(): Unknown modifier '{' error. Been Googling around but I can't figure it out.
Answers.UserDisplayName: Ian Ebden
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-06T15:53:57.973Z
Answers.Text: Ha! Looks like I was trying to be too clever with the regex. Try the amended version to see if that works. ;-) `{% if (key matches '[a-z][a-z]') and (key != 'zz') %}`
Answers.UserDisplayName: Steve Rowling
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-06T15:55:18.167Z
Answers.Text: Hehe, nearly there! preg_match(): Unknown modifier '['
Answers.UserDisplayName: Ian Ebden
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-06T15:57:22.433Z
Answers.Text: Oops, looks like I forgot to enclose the pattern in slashes. This _should_ work now: `{% if (key matches '/[a-z][a-z]/') and (key != 'zz') %}`
Answers.UserDisplayName: Steve Rowling
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-06T16:03:51.450Z
Answers.Text: Thnx. Well, no errors this time but no output either.
Answers.UserDisplayName: Ian Ebden
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-06T16:23:29.460Z
Answers.Text: OK, I see what is happening. `craft.i18n.getLocaleData().getAllTerritories() ` returns a simple array with numeric keys. It doesn't keep the territory keys from the Yii data file. I'm not sure you can do what you want to do natively in Craft, but it looks like John D. Wells' [Territories][1] [1]:https://github.com/johndwells/craft.territories fieldtype plugin may provide what you need. You don't need to use the fieldtype as there is a Twig variable provided that gives you an array of localised territory names, excluding the regions. More details in the edited answer above.
Answers.UserDisplayName: Steve Rowling
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-06T16:49:54.957Z
Answers.Text: Thanks Steve. I did start off with that plugin but I couldn't order the list, and just wanted to do it natively if poss. I'll have a fiddle but thanks, I should be good from here.
Answers.UserDisplayName: Ian Ebden
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-06T13:33:30.343Z
Answers.LastActivityDate: 2017-03-06T16:23:26.253Z
Answers.LastEditDate: 2017-03-06T16:23:26.253Z
Answers.UserDisplayName: Steve Rowling
Body: <p>Wonder if you can help? Got a booking form on a multi-locale site and I need to include the user's country in the form. I'm using Craft's LocaleData class to output locale-specific locales (e.g. Angleterre for England)...</p>
  
  <pre><code>&lt;select name="country" required&gt;
  {% for country in craft.i18n.getLocaleData().getAllTerritories() %}
      &lt;option&gt;{{ country }}&lt;/option&gt;
  {% endfor %}&lt;/select&gt;
  </code></pre>
  
  <p>Works great except it outputs stuff I don't need like "World", "Oceana", "Ascension Island" etc... Is there any way to control the output, like maybe show countries only and not regions?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-06T11:17:40.700Z
Comments.Text: I think it should be `{{ country.name }}` now it wont output anything good if im right.
Comments.UserDisplayName: Justin Dekkers
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-06T11:28:08.300Z
Comments.Text: Yeah that throws an error.
Comments.UserDisplayName: Ian Ebden
Tags: <localization>
Title: Locale-specific country select menu
ThreadText: # Locale-specific country select menu
  
  (Asked by: username_0 on 2017-03-06)
  
  Wonder if you can help? Got a booking form on a multi-locale site and I need to include the user's country in the form. I'm using Craft's LocaleData class to output locale-specific locales (e.g. Angleterre for England)...
  
  ```
  <select name="country" required>
  {% for country in craft.i18n.getLocaleData().getAllTerritories() %}
      <option>{{ country }}</option>
  {% endfor %}</select>
  
  ```
  
  Works great except it outputs stuff I don't need like "World", "Oceana", "Ascension Island" etc... Is there any way to control the output, like maybe show countries only and not regions?
  
  **Tags:** localization
  
  > **Comments:**
  > **username_1**: I think it should be `{{ country.name }}` now it wont output anything good if im right.  
  > **username_0**: Yeah that throws an error.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-03-06. Score: 1
  
  If you look at [the data file for a locale in Yii](https://github.com/pixelandtonic/Craft-Release/blob/master/app/framework/i18n/data/en_gb.php) you can see that the territories property includes regions and continents as you've found. These all have keys with numeric values, whereas countries have two character keys. Using this knowledge, you can loop over the keys and values of the territories array as you are doing, but only output those with two character keys. You'll also probably want to omit the `Unknown Region` value which has a key of `zz`.
  
  Untested, but this should work:
  
  ```
  <select name="country" required>
      {% for key, value in craft.i18n.getLocaleData().getAllTerritories() %}
          {% if (key matches '/[a-z][a-z]/') and (key != 'zz') %}
              <option>{{ value }}</option>
          {% endif %}
      {% endfor %}
  </select>
  
  ```
  
  ---
  
  EDIT
  
  OK, so my original idea doesn't work as `craft.i18n.getLocaleData().getAllTerritories()` doesn't preserve the territory array keys from the Yii i18n data files.
  
  I'm not sure you can do what you want to do natively in Craft, but it looks like [John D. Wells' Territories fieldtype plugin](https://github.com/johndwells/craft.territories) may provide what you need. You don't need to use the fieldtype as there is an undocumented Twig variable provided that gives you an array of localised territory names, excluding the regions. Try this:
  
  ```
  <select name="country" required>
      {% for country in craft.territories.getTerritories() %}
          <option>{{ country }}</option>
      {% endfor %}
  </select>
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks username_2. I get a preg_match(): Unknown modifier '{' error. Been Googling around but I can't figure it out.  
  > **username_2**: Ha! Looks like I was trying to be too clever with the regex. Try the amended version to see if that works. ;-) `{% if (key matches '[a-z][a-z]') and (key != 'zz') %}`  
  > **username_0**: Hehe, nearly there! preg_match(): Unknown modifier '['  
  > **username_2**: Oops, looks like I forgot to enclose the pattern in slashes. This _should_ work now: `{% if (key matches '/[a-z][a-z]/') and (key != 'zz') %}`  
  > **username_0**: Thnx. Well, no errors this time but no output either.  
  > **username_2**: OK, I see what is happening. `craft.i18n.getLocaleData().getAllTerritories() ` returns a simple array with numeric keys. It doesn't keep the territory keys from the Yii data file. I'm not sure you can do what you want to do natively in Craft, but it looks like John D. Wells' [Territories][1] [1]:https://github.com/johndwells/craft.territories fieldtype plugin may provide what you need. You don't need to use the fieldtype as there is a Twig variable provided that gives you an array of localised territory names, excluding the regions. More details in the edited answer above.  
  > **username_0**: Thanks username_2. I did start off with that plugin but I couldn't order the list, and just wanted to do it natively if poss. I'll have a fiddle but thanks, I should be good from here.  
  
  ---
  
  