A PhileCMS plugin that generates a hierarchy tree that can be used to make nested navigation menus.
Install via composer
composer require "gibbs/phile-sub-navigation:1.*"
Install via git
Clone this repository from the phile
directory into
plugins/gibbs/phileSubNavigation
. E.g:
git clone git@github.com:Gibbs/phileSubNavigation.git plugins/gibbs/phileSubNavigation
Manual Install
Download and extract the contents into: plugins/gibbs/phileSubNavigation
Activate the plugin in your config.php
file:
$config['plugins']['gibbs\\phileSubNavigation'] = array('active' => true);
This plugin returns a variable named navigation
. Each item in the site
hierarchy has the following parameters:
active
- True when the item is the current pagelevel
- How deep the current page is nested.meta
- The associated pages meta informationpath
- The current path e.g.blog/post
parent
- The pages parenturi
- An alias ofpath
url
- The full URL to the page
To be flexible NO HTML is generated by this plugin - that is the responsibility of the template engine you are using.
More examples are available on the wiki
Children of a particular path, for example /blog/
can be used by
referencing the children key.
Twig - List /blog/ children
<ul>
{% for item in navigation.blog.children %}
<li>
<a href="{{ item.uri }}">{{ item.meta.title }}</a>
</li>
{% endfor %}
</ul>
Twig - List /blog/archive/ children
<ul>
{% for item in navigation.blog.children.archive.children %}
{% if item.active %}
<li class="active">
{% else %}
<li>
{% endif %}
<a href="{{ item.uri }}">{{ item.meta.title }}</a>
</li>
{% endfor %}
</ul>
Twig - Entire site hierarchy example
<!-- Twig Macro -->
{% macro sub_navigation(navigation) %}
{% import _self as macros %}
{% for item in navigation %}
<li>
<a href="{{ item.uri }}">{{ item.meta.title }}</a>
{% if item.children %}
<ul>
{{ macros.sub_navigation(item.children) }}
</ul>
{% endif %}
</li>
{% endfor %}
{% endmacro %}
{% import _self as macros %}
<ul>{{ macros.sub_navigation(navigation) }}</ul>
To debug the plugin output set 'print' => true
inside the plugins
config.php
file.
Caching is disabled by default and depends on
phile\\simpleFileDataPersistence
(enabled by default).
To enable caching edit the plugins config.php
file and set cache to
true.
NOTE: Caching will cause some parameters such as active
to stop
working.