PhileCMS Sub Navigation
A PhileCMS plugin that generates a
hierarchy tree that can be used to make nested navigation menus., (*1)
1. Installation
Install via composer, (*2)
composer require "gibbs/phile-sub-navigation:1.*"
Install via git, (*3)
Clone this repository from the phile
directory into
plugins/gibbs/phileSubNavigation
. E.g:, (*4)
git clone git@github.com:Gibbs/phileSubNavigation.git plugins/gibbs/phileSubNavigation
Manual Install, (*5)
Download and extract the contents into: plugins/gibbs/phileSubNavigation
, (*6)
2. Plugin Activation
Activate the plugin in your config.php
file:, (*7)
$config['plugins']['gibbs\\phileSubNavigation'] = array('active' => true);
3. Parameters
This plugin returns a variable named navigation
. Each item in the site
hierarchy has the following parameters:, (*8)
-
active
- True when the item is the current page
-
level
- How deep the current page is nested.
-
meta
- The associated pages meta information
-
path
- The current path e.g. blog/post
-
parent
- The pages parent
-
uri
- An alias of path
-
url
- The full URL to the page
4. Example Usage
To be flexible NO HTML is generated by this plugin - that is the responsibility
of the template engine you are using., (*9)
More examples are available on the
wiki, (*10)
Children of a particular path, for example /blog/
can be used by
referencing the children key., (*11)
Twig - List /blog/ children, (*12)
Twig - List /blog/archive/ children, (*13)
{% for item in navigation.blog.children.archive.children %}
{% if item.active %}
-
{% else %}
-
{% endif %}
{{ item.meta.title }}
{% endfor %}
Twig - Entire site hierarchy example, (*14)
{% 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 %}
{{ macros.sub_navigation(navigation) }}
To debug the plugin output set 'print' => true
inside the plugins
config.php
file., (*15)
4. Caching
Caching is disabled by default and depends on
phile\\simpleFileDataPersistence
(enabled by default)., (*16)
To enable caching edit the plugins config.php
file and set cache to
true., (*17)
NOTE: Caching will cause some parameters such as active
to stop
working., (*18)