Created
May 11, 2017 22:32
-
-
Save vinicius5581/e6bf7679ee992c426cdc81bfee72af8b to your computer and use it in GitHub Desktop.
Grav Navigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requirements: | |
// There are two types of pages on my project and they can only bee seen if the user is logged in. | |
// Some pages requires the user to have site.docs permissions and the other require the user to | |
// have site.staff permissions in order to see the pages. | |
// I expect the same behavior on my menu and I would like the menu items (links to the pages) | |
// to be visible only if the user has the proper permissions. | |
// The following code is showing all menu links to the users with side.docs permissions. | |
{% macro loop(page) %} | |
{% for p in page.children.visible %} | |
{% set current_page = (p.active or p.activeChild) ? 'active' : '' %} | |
{% 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 }} | |
<span></span> | |
</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 %} | |
{% if authorize(['site.docs']) %} | |
<ul class="navigation"> | |
{% if config.plugins.login.enabled and grav.user.username %} | |
<li>{% include 'partials/login-status.html.twig' %}</li> | |
{% endif %} | |
{% 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 %} | |
</ul> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment