<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>

CC BY-SA 3.0
2015-12-15T17:03:48.513Z
2015-12-15T17:03:48.513Z
Luke Pearce
<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>

<matrix><structure>
Loop through structure entry types and matrix blocks
# 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') %}


    {# 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 %}


{% 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 %}
   {{ block.title }}
{% endfor %}

{# Content #}
{% for block in entry.contentBlock %}
   
     {{ block.body }}
   
{% 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.


---

