2

I'm building an overview page that will show a title, thumbnail, etc of the pages inside the structure. I want the nav children to start at the parent page we're currently on. I can get the correct elements to display - they just don't have any entry data like title. If there's a better way to approach this let me know.

{% set overview = (entry.level == 1) ? entry : entry.getAncestors().level(1).first() %}

{% nav entry in overview %}

{{ cycle(['<div class="overviewrow">', '', '', ''], loop.index0)|raw }}
    <div class="col">
        <a class="marketlink href="{{ entry.url }}">
        <div class="marketwrap">
            {% for block in entry.contents.type('image').limit(1) %}
            {% if block.image | length %}
            {% for image in block.image.limit(1) %}    
                      <img src="{{ image.getUrl('blogThumb')}}" alt="{{ image.altText }}">   
            {% endfor %} 
            {% else %}
                      <img src="/something.jpg">
            {% endif %} 
          {% endfor %} 
                      <div>{{ entry.title }}</div>
        </div></a></div>
        {% ifchildren %}
                {% children %}
        {% endifchildren %}

  {{ cycle(['', '', '', '</div>'], loop.index0)|raw }}


 {% endnav %}
3

You don't necessarily need to use the nav tag, you can just spin through the entries in a normal {% for entry in entries %} loop, making use of the level property and the getDescendants method.

There are some good suggestions for more complicated nav code in this answer:

How do you handle complex navigation in Craft?

and there's some good pointers in the answers to this question:

Custom or complex nav tag

| improve this answer | |
  • I tried following one of the examples but apparently it's no correct. Now it's only returning the parent page name for each child and no other entry data. {% set pages = craft.entries.section('pages').id('not 1').level(1) %} {% for page in pages %} {% if page.hasDescendants %} <div>{{ entry.title }}</div> {% endif %} {% endfor %} – glider Aug 8 '16 at 22:25
  • @David - Have you tried it without the .level(1)? It's my understanding that by adding this, you are saying you only want the top level entries returned, so in effect you are saying don't fetch the children. – Steve Holland Aug 9 '16 at 10:11

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.