5

I have created a Global with the handle 'footer', which contains a Matrix field 'links' and I'm trying to get this into a template, but I can't seem to get this to work.

The 'links' Matrix contains a Block Type 'navigation' with a Plain Text field 'navigationHeadline' and a Table field 'navigationLinks'. The table field contains 'linkLabel' and 'linkUrl' columns (see attached image).

I'm ultimately creating my navigation in a Global with a Headline and some Links and the Headline should only appear if each block has some links;

{% for block in entry.links %}
    {% if entry.navigationLinks | length %}
        <h3>{{ block.navigationHeadline }}</h3>
        {# Show the navigationHeadline if it has links #}
        <ul>
            {% for row in entry.navigationLinks %}
                <li>{{ row.linkLabel }} - {{ row.linkUrl }}</li>
            {% endfor %}
        </ul>
    {% endif %}
{% endfor %}

I wondered if anyone can help me resolve my obvious errors. Thanks.

Screenshot of Global

6

Not sure why you're referencing "entry" in your code, I'd think the code should be:

{% for block in footer.links %}
  {% if block.navigationLinks | length %}
    <h3>{{ block.navigationHeadline }}</h3>
    {# Show the navigationHeadline if it has links #}
    <ul>
      {% for row in block.navigationLinks %}
        <li>{{ row.linkLabel }} - {{ row.linkUrl }}</li>
      {% endfor %}
    </ul>
  {% endif %}
{% endfor %}

So, "links" is the matrix on your "footer" global, which you can access from anywhere. You loop over that, get a block for each matrix block, and access "navigationHeadline" and "navigationLinks" through that.

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.