gibbs/phile-sub-navigation

This package is abandoned and no longer maintained. No replacement package was suggested.

Generates a philecms nested hierarchy

1.0.1 2014-07-07 20:25 UTC

This package is auto-updated.

Last update: 2021-11-18 21:13:21 UTC


README

A PhileCMS plugin that generates a hierarchy tree that can be used to make nested navigation menus.

1. Installation

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

2. Plugin Activation

Activate the plugin in your config.php file:

$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:

  • 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.

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.

4. Caching

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.