Navigation Problem

I have a really complex navigation with:
main pages > sub pages > sub pages with moduler content

My navigation just works fine with this code on the main pages:

{% for page in pages.children %}
{% if page.active %}
{% if page.children %}
{% for child in page.children %}
{% if child.visible %}


  • {{ child.menu }}

  • {% if child.children %}
    {% for lilchild in child.children %}
    {% if lilchild.visible %}
    {% set current_lil = (lilchild.active or lil.activeChild) ? ‘active’ : ‘’ %}
  • {{ lilchild.menu }}

  • {% endif %}
    {% endfor %}
    {% endif %}

{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}

But when I want to render the navigation with this code, nothing renders. I know what the problem is, just want to render the same menu on the sub pages with modular content corresponding to there main page.

Thanks

I was following ok up to this line:

@valen
I know what the problem is, just want to render the same menu on the sub pages with modular content corresponding to there main page.

What does this mean? Menu works on all pages, just not on the page with teh modular content?

Also please, please, please paste big blocks of code between triple back ticks (```)

Sorry for the code…
Sadly, I can’t provide you a demo because it’s under a .dmz .
The menu works only on the main pages.

it ‘could’ be that your looping over the pages and using page which is already a variable assigned to the Twig environment. Try changing this page variable to p or something more unique.

maybe something to run this script always relative to the root? A loop or something? I’m really a newbie to grav…

or can i access the page template name with a function? like {{ page.template }} ?

pages should always be available and always contains ‘all’ the pages.

{{ page.template }} should return the template name, but why do you need it?

Maybe just send me a zip file of your site to andy at getgrav dot org, and i’ll try to get a better understanding of your issue.

Finally I can figured it out.

Here is the final code:

{% if page.template == "main" %}
    {% set main = page %}
{% elseif page.template == "sub" %}
    {% set main = page.parent %}
{% elseif page.template == "page" %}
    {% set main = page.parent.parent %}
{% endif %}
   
    
{% if main.children %}
    {% for child in main.children %}
        {% if child.visible %}
        
        <ul class="app--side_menu-block">
            <li class="head"><a href="{{ child.url }}">{{ child.menu }}</a></li>
             
            {% if child.children %}
                {% for lilchild in child.children %}
                    {% if lilchild.visible %}
                    {% set current_lil = (lilchild.active or lil.activeChild) ? 'active' : '' %}
                    
                    <li class="item {{ current_lil }}"><a href="{{ lilchild.url }}">{{ lilchild.menu }}</a></li>
                    
                    {% endif %}
                {% endfor %}
            {% endif %}
            
        </ul>
        
        {% endif %}
    {% endfor %}
{% endif %}

Maybe there is a better way to do it, but it just works fine.

I am glad it’s working, but still am not sure why:

{% for child in pages.children %}

Wouldn’t work for all pages? That’s what I do on my test sites and have never had a problem.

Nope… Because I’m rendering the “main” pages in a different navigation. I just needed to list all the “sub” pages with there “pages” in

    s as you can see above.

Ok, i’ll leave it be! There really is no wrong answer anyway :slight_smile: