Answers.Body: <p>Personally, in situations like this (particularly if there's only a few items, and no easy way to automate it with inflection or similar,) I just use an array as a kind of dictionary.</p>
  
  <pre><code>{% set sectionHandlesBySegment = { 
      'hotel-california': 'hotelsCalifornia',
      'hotel-florida':    'hotelsFlorida' }
  %}
  
  {% if not craft.request.getSegment(2) in sectionHandlesBySegment|keys %}
      {% exit 404 %}
  {% endif %}
  
  {% set sectionHandle = sectionHandlesBySegment[craft.request.getSegment(2)] %}
  {% set hotels = craft.entries.section(sectionHandle) %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-09T15:58:34.367Z
Answers.LastActivityDate: 2014-09-09T15:58:34.367Z
Answers.UserDisplayName: Mike Pepper
Answers.Body: <p>You could use the <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel#setting-the-parameters" rel="nofollow">"object syntax"</a> of the ElementCriteriaModel, in combination with an <a href="http://twig.sensiolabs.org/doc/tags/if.html" rel="nofollow">if-statement</a>:</p>
  
  <pre class="lang-twig prettyprint-override"><code>// Checks if the 2. segment of the url is 'hotel-california'
  {% if craft.request.getSegment(2) == 'hotel-california' %}
      {% set params = { section: 'hotelCalifornia' } %}
  {% else %}
      {% set params = { section: 'anotherSection' } %}
  {% endif %}
  
  {% for entry in craft.entries(params) %}
      {{ entry.title }}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-09-09T15:43:58.957Z
Answers.LastActivityDate: 2014-09-09T15:43:58.957Z
Answers.UserDisplayName: Victor
Body: <p>I'd like to use a single template to pull in entries from different channels based on url segment 2. But it seems I need to change the section attribute to match the url segment:</p>
  
  <pre><code>{% for entry in craft.entries.section('mySection').find() %}
  </code></pre>
  
  <p>Given that the url segment and section handle are different, can this be done?</p>
  
  <p>For example the url segment might be <code>hotel-california</code> and the section handle of the section I want entries from could be <code>hotelCalifornia</code> or <code>hotelsInCalifornia</code>.</p>
  
Tags: <templating>
Title: Use a single template to display entries from different channels?
ThreadText: # Use a single template to display entries from different channels?
  
  (Asked by: username_0 on 2014-09-09)
  
  I'd like to use a single template to pull in entries from different channels based on url segment 2. But it seems I need to change the section attribute to match the url segment:
  
  ```
  {% for entry in craft.entries.section('mySection').find() %}
  
  ```
  
  Given that the url segment and section handle are different, can this be done?
  
  For example the url segment might be `hotel-california` and the section handle of the section I want entries from could be `hotelCalifornia` or `hotelsInCalifornia`.
  
  **Tags:** templating
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-09-09. Score: 3 | Accepted answer
  
  Personally, in situations like this (particularly if there's only a few items, and no easy way to automate it with inflection or similar,) I just use an array as a kind of dictionary.
  
  ```
  {% set sectionHandlesBySegment = { 
      'hotel-california': 'hotelsCalifornia',
      'hotel-florida':    'hotelsFlorida' }
  %}
  
  {% if not craft.request.getSegment(2) in sectionHandlesBySegment|keys %}
      {% exit 404 %}
  {% endif %}
  
  {% set sectionHandle = sectionHandlesBySegment[craft.request.getSegment(2)] %}
  {% set hotels = craft.entries.section(sectionHandle) %}
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2014-09-09. Score: 1
  
  You could use the ["object syntax"](http://buildwithcraft.com/docs/templating/elementcriteriamodel#setting-the-parameters) of the ElementCriteriaModel, in combination with an [if-statement](http://twig.sensiolabs.org/doc/tags/if.html):
  
  ```twig
  // Checks if the 2. segment of the url is 'hotel-california'
  {% if craft.request.getSegment(2) == 'hotel-california' %}
      {% set params = { section: 'hotelCalifornia' } %}
  {% else %}
      {% set params = { section: 'anotherSection' } %}
  {% endif %}
  
  {% for entry in craft.entries(params) %}
      {{ entry.title }}
  {% endif %}
  
  ```
  
  
  ---
  
  