1

That is written so inefficently:

{% set indexNavi = craft.entries.section('pageContent').level(1).all() %}
{% set bookingLink = craft.entries.section('booking').all() %}

<ul class="navList">
  {% for item in indexNavi %}
    <li>
      <a class="btnLink" href="{{ item.url }}">{{ item.title }}</a>
    </li>
  {% endfor %}
  {% for item in bookingLink %}
    <li>
      <a class="btnLink" href="{{ item.url }}">{{ item.title }}</a>
    </li>
  {% endfor %}
</ul>

Is there a better way?

I wanted to creat a single variable:

{% set merger = craft.entries.section(['pageContent','booking']).level(1).all() %}

But this only outputs the pageContent. I guess because booking is a single section and therefore has no level?

2

But this only outputs the pageContent. I guess because booking is a single section and therefore has no level?

In short, yes. It's not super clean but you could fetch everything without worrying about level:

{% set merger = craft.entries.section(['pageContent','booking']).all() %}

Then check for level in your loop ('normal' entries return null as a level)

{% for item in merger %}
    {% if item.level is null or item.level == 1 %}
        {{ item.title }}<br>
    {% endif %}
{% endfor %}
| 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.