Answers.Body: <p>If I was building a single page website I might create a matrix field with different blocks for each "page".</p>
  
  <pre><code>{# Navigation #}
  {% for block in entry.contentBlock %}
     &lt;li&gt;&lt;a href="#{{ block.slug }}"&gt;{{ block.title }}&lt;/a&gt;&lt;/li&gt;
  {% endfor %}
  
  {# Content #}
  {% for block in entry.contentBlock %}
     &lt;section id="{{ block.slug }}"&gt;
       {{ block.body }}
     &lt;/section&gt;
  {% endfor %}
  </code></pre>
  
  <p>This will allow someone to re-order "pages" easily under one entry. You can also create several different block types with different fields in if these "pages" needed to be different.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-15T17:03:48.513Z
Answers.LastActivityDate: 2015-12-15T17:03:48.513Z
Answers.UserDisplayName: Luke Pearce
Body: <p>Single page website. Navigation based on a Structure section (anchor links). Entries depend on entryTypes.</p>
  
  <pre><code>{# set each section ID with for anchor navigation #}
  {% for page in craft.entries.section('pages') %}
  &lt;section id ="{{ page.slug }}"&gt;
  
      {# check the slug to get the Matrix entries related to the (html) section ID #}
      {% if page.slug == 'home' %}
          {# get the entries for the entry.type #}
          {% set entries = craft.entries.type('pagesHome') %}
              {# loop through the block types and entries #}
              {% for block in page.matrixFieldHandle.type('matrixBlockHandle') %}
                  {{ block.title }}
              {% endfor %}
      {% endif %}
  
      {# and so on.... #}
      {% if page.slug == 'about' %}
          ......
      {% endif %}
  
  &lt;/section&gt;
  {% endfor %}
  </code></pre>
  
  <p>Questions: am I setting up this single page website in a too complicated way with too many DB queries? 
  Thanks for suggestions!</p>
  
Tags: <matrix><structure>
Title: Loop through structure entry types and matrix blocks
ThreadText: # Loop through structure entry types and matrix blocks
  
  (Asked by: username_0 on 2015-12-15)
  
  Single page website. Navigation based on a Structure section (anchor links). Entries depend on entryTypes.
  
  ```
  {# set each section ID with for anchor navigation #}
  {% for page in craft.entries.section('pages') %}
  <section id ="{{ page.slug }}">
  
      {# check the slug to get the Matrix entries related to the (html) section ID #}
      {% if page.slug == 'home' %}
          {# get the entries for the entry.type #}
          {% set entries = craft.entries.type('pagesHome') %}
              {# loop through the block types and entries #}
              {% for block in page.matrixFieldHandle.type('matrixBlockHandle') %}
                  {{ block.title }}
              {% endfor %}
      {% endif %}
  
      {# and so on.... #}
      {% if page.slug == 'about' %}
          ......
      {% endif %}
  
  </section>
  {% endfor %}
  
  ```
  
  Questions: am I setting up this single page website in a too complicated way with too many DB queries?
  Thanks for suggestions!
  
  **Tags:** matrix, structure
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-12-15. Score: 1
  
  If I was building a single page website I might create a matrix field with different blocks for each "page".
  
  ```
  {# Navigation #}
  {% for block in entry.contentBlock %}
     <li><a href="#{{ block.slug }}">{{ block.title }}</a></li>
  {% endfor %}
  
  {# Content #}
  {% for block in entry.contentBlock %}
     <section id="{{ block.slug }}">
       {{ block.body }}
     </section>
  {% endfor %}
  
  ```
  
  This will allow someone to re-order "pages" easily under one entry. You can also create several different block types with different fields in if these "pages" needed to be different.
  
  
  ---
  
  