1

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!

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.