Answers.Body: <pre><code>{% set sidebarNav = entry.getChildren() %}
  
  {% if sidebarNav | length %}
  
          &lt;ul&gt;
              {% for entry in sidebarNav %}
              &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
              {% endfor %}
          &lt;/ul&gt;
  {% endif %}
  </code></pre>
  
  <p>Although I'm not sure what you mean by all singles? Is this what you're after? It will return all children of the current structure page.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-21T11:32:06.710Z
Answers.Text: That doesn't output anything. By "All singles" I mean all the pages that need to appear in the navigation are Singles.
Answers.UserDisplayName: darylknight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-21T12:12:33.067Z
Answers.Text: Are these singles related to each relevant structure page? If so could you do a loop through the related field to display them?
  
  {% for entry in entry.relatedFieldName %}
   <a href="{{ entry.url }}">{{ entry.title }}</a>
  {% endfor %}
Answers.UserDisplayName: Mart
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-21T12:47:42.817Z
Answers.Text: @Mart that wouldn't work because the entries field to do the relations is added to the structure entries.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-21T10:24:19.497Z
Answers.LastActivityDate: 2014-08-21T10:24:19.497Z
Answers.UserDisplayName: Mart
Answers.Body: <p>You first have to get the corresponding entry in your "menu" structure and then build your navigation upon that item.</p>
  
  <p>Use the <a href="http://buildwithcraft.com/docs/relations#the-relatedTo-param"><code>relatedTo()</code></a> parameter for that. The <code>entry</code> entry model that you automatically get on that single template is the <code>targetElement</code> of that relation, but you should be fine using the less specific <code>element</code> property used with the short syntax <code>relatedTo(myEntryModel)</code>.</p>
  
  <pre><code>{# Get the (one!) related entry from the "menu" structure #}
  {% set menuItem = craft.entries.section('menu').relatedTo(entry).first() %}
  
  {# Check if there are descendant entries #}
  {% if menuItem.hasDescendants() %}
  
      {# Get entries to build the sub-menu #}
      {% set subMenu = craft.entries.descendantOf(menuItem) %}
  
      {# Output the sub menu #}
      &lt;ul&gt;
          {% nav link in subMenu %}
              &lt;li&gt;
                  &lt;a href="{{ link.url }}"&gt;{{ link.title }}&lt;/a&gt;
                  {% ifchildren %}
                      &lt;ul&gt;
                          {% children %}
                      &lt;/ul&gt;
                  {% endifchildren %}
              &lt;/li&gt;
          {% endnav %}
      &lt;/ul&gt;
  
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-21T13:28:10.970Z
Answers.Text: Hey carlcs - thank you! That code worked perfectly (after I fixed the variable names). Makes perfect sense when you read the code, it's just knowing the correct syntax.
Answers.UserDisplayName: darylknight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-21T12:42:08.403Z
Answers.LastActivityDate: 2014-08-21T13:39:53.263Z
Answers.LastEditDate: 2014-08-21T13:39:53.263Z
Answers.UserDisplayName: carlcs
Body: <p>I've got a single structure menu for my entire site which consists of a title and a single related entry. I use that to output the main menu, which uses this code:</p>
  
  <pre><code>&lt;section class="top-bar-section"&gt;
      &lt;ul class="right"&gt;
          {% nav link in craft.entries.section('menu') %}
          &lt;li class="{% if link.slug == craft.request.getSegment(1) %}active{% endif %} {% if link.hasDescendants() %}has-dropdown{% endif %}"&gt; {# Checks if              the page link is the same as the slug of current page #}
              &lt;a href="{{ link.relatedEntry[0].url }}"&gt;{{link.title}}&lt;/a&gt;
              {% ifchildren %}
              &lt;ul class="dropdown"&gt;
                  {% children %}
              &lt;/ul&gt;
              {% endifchildren %}
          &lt;/li&gt;
          {% endnav %}
      &lt;/ul&gt;
  &lt;/section&gt;
  </code></pre>
  
  <p>On the top level pages, in their template they have a sidebar which should output the menu items in that main section - all singles. Is there a way to do this or do I need to create separate Structures for each section?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T12:51:23.857Z
Comments.Text: Why don't use use the structure for the content also? I don't see the benefits of using a bunch of singles and then have to manage the structure of them in a separate structure section using entries fields.
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T13:27:21.710Z
Comments.Text: with "top level pages" you meant the singles, related to a top level entry from your structure, right?
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T13:29:25.583Z
Comments.Text: Practically every page on the site has a different layout - and as far as I can tell it's not possible to set different templates for entries in a Structure channel
Comments.UserDisplayName: darylknight
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T13:31:15.717Z
Comments.Text: Yes you can! That's where [entry types](http://buildwithcraft.com/help/entry-type-templates) come into the game.
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T13:43:01.697Z
Comments.Text: Entry types let you use different fields, not different templates (as far as I can tell)
Comments.UserDisplayName: darylknight
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T13:43:53.617Z
Comments.Text: Hey code knight, you didn't click the link I provided!
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T13:47:34.377Z
Comments.Text: Ahh ok I see - managed to miss that in the docs, thanks. Dynamic templates. Now my head is spinning with flexibility again ><
Comments.UserDisplayName: darylknight
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T13:49:46.467Z
Comments.Text: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/16589/discussion-between-codeknight-and-carlcs).
Comments.UserDisplayName: darylknight
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-08-21T14:59:03.360Z
Comments.Text: codeknight, you could also use a combine approach like I outlined in this answer: http://craftcms.stackexchange.com/a/1474/125
Comments.UserDisplayName: carlcs
Tags: <structure>
Title: How to output a structure sub-navigation of current page
ThreadText: # How to output a structure sub-navigation of current page
  
  (Asked by: username_0 on 2014-08-21)
  
  I've got a single structure menu for my entire site which consists of a title and a single related entry. I use that to output the main menu, which uses this code:
  
  ```
  <section class="top-bar-section">
      <ul class="right">
          {% nav link in craft.entries.section('menu') %}
          <li class="{% if link.slug == craft.request.getSegment(1) %}active{% endif %} {% if link.hasDescendants() %}has-dropdown{% endif %}"> {# Checks if              the page link is the same as the slug of current page #}
              <a href="{{ link.relatedEntry[0].url }}">{{link.title}}</a>
              {% ifchildren %}
              <ul class="dropdown">
                  {% children %}
              </ul>
              {% endifchildren %}
          </li>
          {% endnav %}
      </ul>
  </section>
  
  ```
  
  On the top level pages, in their template they have a sidebar which should output the menu items in that main section - all singles. Is there a way to do this or do I need to create separate Structures for each section?
  
  **Tags:** structure
  
  > **Comments:**
  > **username_1**: Why don't use use the structure for the content also? I don't see the benefits of using a bunch of singles and then have to manage the structure of them in a separate structure section using entries fields.  
  > **username_1**: with "top level pages" you meant the singles, related to a top level entry from your structure, right?  
  > **username_0**: Practically every page on the site has a different layout - and as far as I can tell it's not possible to set different templates for entries in a Structure channel  
  > **username_1**: Yes you can! That's where [entry types](http://buildwithcraft.com/help/entry-type-templates) come into the game.  
  > **username_0**: Entry types let you use different fields, not different templates (as far as I can tell)  
  > **username_1**: Hey code knight, you didn't click the link I provided!  
  > **username_0**: Ahh ok I see - managed to miss that in the docs, thanks. Dynamic templates. Now my head is spinning with flexibility again ><  
  > **username_0**: Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/16589/discussion-between-codeknight-and-username_1).  
  > **username_1**: codeknight, you could also use a combine approach like I outlined in this answer: http://craftcms.stackexchange.com/a/1474/125  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-08-21. Score: 5 | Accepted answer
  
  You first have to get the corresponding entry in your "menu" structure and then build your navigation upon that item.
  
  Use the [`relatedTo()`](http://buildwithcraft.com/docs/relations#the-relatedTo-param) parameter for that. The `entry` entry model that you automatically get on that single template is the `targetElement` of that relation, but you should be fine using the less specific `element` property used with the short syntax `relatedTo(myEntryModel)`.
  
  ```
  {# Get the (one!) related entry from the "menu" structure #}
  {% set menuItem = craft.entries.section('menu').relatedTo(entry).first() %}
  
  {# Check if there are descendant entries #}
  {% if menuItem.hasDescendants() %}
  
      {# Get entries to build the sub-menu #}
      {% set subMenu = craft.entries.descendantOf(menuItem) %}
  
      {# Output the sub menu #}
      <ul>
          {% nav link in subMenu %}
              <li>
                  <a href="{{ link.url }}">{{ link.title }}</a>
                  {% ifchildren %}
                      <ul>
                          {% children %}
                      </ul>
                  {% endifchildren %}
              </li>
          {% endnav %}
      </ul>
  
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: Hey username_1 - thank you! That code worked perfectly (after I fixed the variable names). Makes perfect sense when you read the code, it's just knowing the correct syntax.  
  
  ---
  
  ### Answer by username_2 on 2014-08-21. Score: 1
  
  ```
  {% set sidebarNav = entry.getChildren() %}
  
  {% if sidebarNav | length %}
  
          <ul>
              {% for entry in sidebarNav %}
              <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
              {% endfor %}
          </ul>
  {% endif %}
  
  ```
  
  Although I'm not sure what you mean by all singles? Is this what you're after? It will return all children of the current structure page.
  
  > **Comments:**
  > **username_0**: That doesn't output anything. By "All singles" I mean all the pages that need to appear in the navigation are Singles.  
  > **username_2**: Are these singles related to each relevant structure page? If so could you do a loop through the related field to display them?  {% for entry in entry.relatedFieldName %}  <a href="{{ entry.url }}">{{ entry.title }}</a> {% endfor %}  
  > **username_1**: @username_2 that wouldn't work because the entries field to do the relations is added to the structure entries.  
  
  ---
  
  