Skip to content

Instantly share code, notes, and snippets.

@hughbris
Created May 5, 2018 01:11
Show Gist options
  • Save hughbris/652c5779c18b41821502c1a319deabce to your computer and use it in GitHub Desktop.
Save hughbris/652c5779c18b41821502c1a319deabce to your computer and use it in GitHub Desktop.
Adaptation of Grav navigation partial for menu to show visible modular pages as fragment links
{% macro loop(page) %}
{% set menu_pages = page.children.visible %}
{% for p in menu_pages %}
{% set current_page = (p.active or p.activeChild) ? 'active' : '' %}
{% set has_visible_modular_children = false %}
{% for frag in p.children.modular if frag.header.visible %}
{% set has_visible_modular_children = true %}
{% endfor %}
{% if p.children.visible.count > 0 or has_visible_modular_children %}
<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 }}
<span></span>
</a>
<ul>
{{ _self.loop(p) }}
</ul>
</li>
{% else %}
{% if p.modular %}
{% set url_prefix = (p.parent.active or p.parent.activeChild) ? '' : page.url ~ '/' %}
<li><a href="{{ url_prefix }}#{{ p.header.id }}">{{ p.menu }}</a></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 %}
{% endif %}
{% endfor %}
{% endmacro %}
<ul class="navigation">
{% if theme_config.dropdown.enabled %}
{{ _self.loop(pages) }}
{% else %}
{% for page in pages.children.visible %}
{% set current_page = (page.active or page.activeChild) ? 'active' : '' %}
<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 %}
{% if config.plugins.login.enabled and grav.user.username %}
<li><i class="fa fa-lock"></i> {% include 'partials/login-status.html.twig' %}</li>
{% endif %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment