Answers.Body: <p>A good option here is to make use of <a href="http://buildwithcraft.com/docs/templating/craft.request" rel="nofollow">craft.request</a>. As long as the URL is the section handle, you can do something like this:</p>
  
  <pre><code>{% current_section = craft.request.firstSegment %}
  
  {% for entry in craft.entries.section(current_section).limit(20).find() %}
  ...
  {% endfor %}
  </code></pre>
  
  <p>If the url is mysite.com/news, <code>firstSegment</code> will return 'news', which you can use in your <code>craft.entries</code> call.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>If your URLs need to be different than the section handles, make use of Twig's <a href="http://twig.sensiolabs.org/doc/tags/include.html#include" rel="nofollow">include with</a> tag. For each section, you will need an index.html template with the following:</p>
  
  <pre><code>{% set current_section = 'thisSectionHanle' %}
  {% include listPage.html with current_section %}
  </code></pre>
  
  <p>listPage.html can be the template that has the actual fetch and display logic. Using <code>include with</code>, listPage.html will have access to the <code>current_section</code> variable.</p>
  
  <p>So not <em>perfectly</em> dry, but the main logic chunk will not have to be repeated. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-19T20:49:50.883Z
Answers.Text: Thank you for your reply. This will work for the 'news' section but it does not work when I have sections with handles like 'reasearchUpdates'. Craft does not allow dashes in section names. My url for these entries would like something like mysite.com/research-updates/this-is-the-title
Answers.UserDisplayName: SteveO
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-19T21:06:04.157Z
Answers.Text: Just updated with another option!
Answers.UserDisplayName: Aaron Berkowitz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-19T20:25:46.860Z
Answers.LastActivityDate: 2015-08-19T21:05:54.827Z
Answers.LastEditDate: 2015-08-19T21:05:54.827Z
Answers.UserDisplayName: Aaron Berkowitz
Body: <p>I have several Listing channels that all use the same templates:</p>
  
  <p>E.g.</p>
  
  <p>Templates:</p>
  
  <ul>
  <li>/templates/view/overview.html</li>
  <li>/templates/view/detail.html</li>
  </ul>
  
  <p>Channels</p>
  
  <ul>
  <li>News</li>
  <li>Research Updates</li>
  <li>Upcoming Events</li>
  </ul>
  
  <p>How can I only list the entries for each channel at their respective URL without having to duplicate the templates? </p>
  
  <p>E.g.</p>
  
  <p>"<a href="http://mysite.com/news" rel="nofollow">http://mysite.com/news</a>" should only list the the latest 20 news stories with links to the detail page.</p>
  
  <pre><code>{% for entry in craft.entries.section('news', 'research', 'events').limit(20).find() %}
  &lt;div class="col-sm-6"&gt;
      &lt;h2 class="Heading"&gt;&lt;a href="{{ entry.url }}" title="{{ entry.title }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h2&gt;
      &lt;p class="Date"&gt;{{entry.postDate|date('M j, Y')}}&lt;/p&gt;
      &lt;p&gt;{{ excerpt|length &gt; 250 ? excerpt|slice(0, 200) ~ '...' : excerpt  }}&lt;/p&gt;
      &lt;p&gt;&lt;a href="{{ entry.url }}" title="{{ entry.title }}" class="ReadMore"&gt;Read More&lt;/a&gt;&lt;/p&gt;
  &lt;/div&gt;                          
  </code></pre>
  
  <p>{% endfor %}</p>
  
Tags: <templating>
Title: Need help: Multiple Listing channels with one template. DRY
ThreadText: # Need help: Multiple Listing channels with one template. DRY
  
  (Asked by: username_0 on 2015-08-19)
  
  I have several Listing channels that all use the same templates:
  
  E.g.
  
  Templates:
  
  * /templates/view/overview.html
  * /templates/view/detail.html
  
  Channels
  
  * News
  * Research Updates
  * Upcoming Events
  
  How can I only list the entries for each channel at their respective URL without having to duplicate the templates?
  
  E.g.
  
  "<http://mysite.com/news>" should only list the the latest 20 news stories with links to the detail page.
  
  ```
  {% for entry in craft.entries.section('news', 'research', 'events').limit(20).find() %}
  <div class="col-sm-6">
      <h2 class="Heading"><a href="{{ entry.url }}" title="{{ entry.title }}">{{ entry.title }}</a></h2>
      <p class="Date">{{entry.postDate|date('M j, Y')}}</p>
      <p>{{ excerpt|length > 250 ? excerpt|slice(0, 200) ~ '...' : excerpt  }}</p>
      <p><a href="{{ entry.url }}" title="{{ entry.title }}" class="ReadMore">Read More</a></p>
  </div>                          
  
  ```
  
  {% endfor %}
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-19. Score: 3
  
  A good option here is to make use of [craft.request](http://buildwithcraft.com/docs/templating/craft.request). As long as the URL is the section handle, you can do something like this:
  
  ```
  {% current_section = craft.request.firstSegment %}
  
  {% for entry in craft.entries.section(current_section).limit(20).find() %}
  ...
  {% endfor %}
  
  ```
  
  If the url is mysite.com/news, `firstSegment` will return 'news', which you can use in your `craft.entries` call.
  
  **UPDATE:**
  
  If your URLs need to be different than the section handles, make use of Twig's [include with](http://twig.sensiolabs.org/doc/tags/include.html#include) tag. For each section, you will need an index.html template with the following:
  
  ```
  {% set current_section = 'thisSectionHanle' %}
  {% include listPage.html with current_section %}
  
  ```
  
  listPage.html can be the template that has the actual fetch and display logic. Using `include with`, listPage.html will have access to the `current_section` variable.
  
  So not *perfectly* dry, but the main logic chunk will not have to be repeated.
  
  > **Comments:**
  > **username_0**: Thank you for your reply. This will work for the 'news' section but it does not work when I have sections with handles like 'reasearchUpdates'. Craft does not allow dashes in section names. My url for these entries would like something like mysite.com/research-updates/this-is-the-title  
  > **username_1**: Just updated with another option!  
  
  ---
  
  