0

I've created a new Pure.css based Grav theme as described here.

As they said here at 15. the dropdown should work by default. Actually it doesn't for me.

In the rendered page, the navigation looks like this:

<ul>
  <li class="selected">
    <a href="/">Home </a>
  </li>
  <li class="">
    <a href="/kontakt">Contact</a>
  </li>
</ul>

However, "Home" should have 3 visible sub-pages.

Does anyone know what could be missing here?

This is the default partials/navigation.html.twig:

    {% macro loop(page) %}
        {% for p in page.children.visible %}
            {% set current_page = (p.active or p.activeChild) ? 'selected' : '' %}
            {% if p.children.visible.count > 0 %}
                <li class="has-children {{ current_page }}">
                    <a href="{{ p.url }}">
                        {% if p.header.icon %}<i class="fa fa-{{ p.header.icon }}"></i>{% endif %}
                        {{ p.menu }}
                    </a>
                    <ul>
                        {{ _self.loop(p) }}
                    </ul>
                </li>
            {% else %}
                <li class="{{ current_page }}">
                    <a href="{{ p.url }}">
                        {% if p.header.icon %}<i class="fa fa-{{ p.header.icon }}"></i>{% endif %}
                        {{ p.menu }}
                    </a>
                </li>
            {% endif %}
        {% endfor %}
    {% endmacro %}

    <ul>
        {% if theme_config.dropdown.enabled %}
            {{ _self.loop(pages) }}
        {% else %}
            {% for page in pages.children.visible %}
                {% set current_page = (page.active or page.activeChild) ? 'selected' : '' %}
                <li class="{{ current_page }}">
                    <a href="{{ page.url }}">
                        {% if page.header.icon %}<i class="fa fa-{{ page.header.icon }}"></i>{% endif %}
                        {{ page.menu }}
                    </a>
                </li>
            {% endfor %}
        {% endif %}
        {% for mitem in site.menu %}
            <li>
                <a href="{{ mitem.url }}">
                    {% if mitem.icon %}<i class="fa fa-{{ mitem.icon }}"></i>{% endif %}
                    {{ mitem.text }}
                </a>
            </li>
        {% endfor %}
    </ul>

Yes I should ask that in the GravCMS forums. I registered there 30 days ago but still my account isn't unlocked and no admin answers to my messages. :)

  • No way for someone else to figure this out for you. You'll need to determine if your getting the data needed. Enable debugging in twig and start using `{{ dump() }}` for the variables. – EternalHour Sep 04 '19 at 06:56

1 Answers1

0

I think there is a mistake in the tutorial...

In line 26 in template navigation.html.twig, the variable theme_config is being referenced. However, that variable is not a standard Grav variable and is often defined in templates to point to config.theme.

To solve your issue, replace theme_config in navigation.html.twig, by config.theme or just theme:

line 26: {% if config.theme.dropdown.enabled %}

The variable config.theme points to the file user/themes/yourtheme/yourtheme.yaml or to /user/config/themes/yourtheme.yaml. The latter is used to override settings from /user/themes/yourtheme/yourtheme.yaml and will not be overridden when the theme is updated.

For more info on theme variables see chapter Theme Variables in Grav's documentation.

passerby
  • 1,807
  • 19
  • 26