Answers.Body: <p>I've found what is probably a better solution;</p>
  
  <p>I create a Single section for each Channel/Structure and use that as a directory for that channel/structure. I then loop through all sections and see if they're of the single type, then get the first (and only) entry of that section.</p>
  
  <pre><code>{# Get all Section #}
  {% set sections = craft.sections.getAllSections() %}
  
  {# Loop through all single sections #}
  {% for singleSection in sections if singleSection.type == 'single' %}
  
      {# Get the first (and only) entry of that section #}
      {% set singleEntry = craft.entries.sectionId(singleSection.id).first %}
  
      {# Output #}
       &lt;li class="nav__link"&gt;
          &lt;a href="{{ singleEntry.url }}" class="section-link"&gt;{{ singleSection }}&lt;/a&gt;
      &lt;/li&gt;
  
  {% endfor %}
  </code></pre>
  
  <p>Let me know if you guys have a better way of doing this!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-22T19:48:30.527Z
Answers.Text: This will work fine until you need a `single` that you otherwise do not want to include in the nav. You might be better served by creating a dedicated 'navigation' section/structure , with an entry field that points to the correct page. That way you can control the order and what is and is not included.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-22T20:51:51.837Z
Answers.Text: I've gotten around this problem with a lightswitch field to include that particular entry in the nav or not. As always ymmv.
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-22T18:05:46.413Z
Answers.LastActivityDate: 2016-03-22T18:05:46.413Z
Answers.UserDisplayName: jasonetco
Body: <p>I'm pretty new to Craft, so I'd like to know if there's a best practice when linking to a section, assuming the section has an <code>index.html</code> template for its "homepage."</p>
  
  <p>I'm currently using the following to loop through all Sections and then give me their URL, but in sort of a hacky way. This is one of a couple ways I've found to do this, but my Homepage singlepage entry outputs as <code>http://example.com/__home__</code> which is super weird.</p>
  
  <pre><code>{% set sections = craft.sections.getAllSections() %}  
  
  {% for section in sections %}
      &lt;li class="nav__link" id="nav__link--{{ section.handle }}"&gt;
          &lt;a href="{{ siteUrl }}{{ section.template|split('/')[0] }}"&gt;{{ section }}&lt;/a&gt;
      &lt;/li&gt;
  {% endfor %}
  </code></pre>
  
  <p>```</p>
  
  <p>If the best practice is to do something completely different, then feel free to set me straight! Thanks!</p>
  
Tags: <templating><sections>
Title: Linking to Sections: do it or do something different?
ThreadText: # Linking to Sections: do it or do something different?
  
  (Asked by: username_0 on 2016-03-22)
  
  I'm pretty new to Craft, so I'd like to know if there's a best practice when linking to a section, assuming the section has an `index.html` template for its "homepage."
  
  I'm currently using the following to loop through all Sections and then give me their URL, but in sort of a hacky way. This is one of a couple ways I've found to do this, but my Homepage singlepage entry outputs as `http://example.com/__home__` which is super weird.
  
  ```
  {% set sections = craft.sections.getAllSections() %}  
  
  {% for section in sections %}
      <li class="nav__link" id="nav__link--{{ section.handle }}">
          <a href="{{ siteUrl }}{{ section.template|split('/')[0] }}">{{ section }}</a>
      </li>
  {% endfor %}
  
  ```
  
  ```
  
  If the best practice is to do something completely different, then feel free to set me straight! Thanks!
  
  **Tags:** templating, sections
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-03-22. Score: 1
  
  I've found what is probably a better solution;
  
  I create a Single section for each Channel/Structure and use that as a directory for that channel/structure. I then loop through all sections and see if they're of the single type, then get the first (and only) entry of that section.
  
  ```
  {# Get all Section #}
  {% set sections = craft.sections.getAllSections() %}
  
  {# Loop through all single sections #}
  {% for singleSection in sections if singleSection.type == 'single' %}
  
      {# Get the first (and only) entry of that section #}
      {% set singleEntry = craft.entries.sectionId(singleSection.id).first %}
  
      {# Output #}
       <li class="nav__link">
          <a href="{{ singleEntry.url }}" class="section-link">{{ singleSection }}</a>
      </li>
  
  {% endfor %}
  
  ```
  
  Let me know if you guys have a better way of doing this!
  
  > **Comments:**
  > **username_1**: This will work fine until you need a `single` that you otherwise do not want to include in the nav. You might be better served by creating a dedicated 'navigation' section/structure , with an entry field that points to the correct page. That way you can control the order and what is and is not included.  
  > **username_2**: I've gotten around this problem with a lightswitch field to include that particular entry in the nav or not. As always ymmv.  
  
  ---
  
  