studioespresso / craft-navigate
Navigation plugin for Craft CMS
Installs: 40 000
Dependents: 1
Suggesters: 0
Security: 0
Stars: 26
Watchers: 5
Forks: 7
Open Issues: 4
Type:craft-plugin
Requires
- craftcms/cms: ^5.1.0
Requires (Dev)
- craftcms/ecs: dev-main
- craftcms/phpstan: dev-main
- dev-develop-v5
- v5.x-dev
- 5.1.2
- 5.1.1
- 5.1.0
- 5.0.1
- 5.0.0
- 5.0.0-alpha.4
- 5.0.0-alpha.3
- 5.0.0-alpha.2
- 5.0.0-alpha
- 3.2.1
- 3.2.0
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.2
- 3.0.1
- 3.0.0
- 3.0.0-beta.1
- 2.9.1
- 2.9.0
- 2.8.1
- 2.8.0
- 2.7.8
- 2.7.7
- 2.7.6
- 2.7.5
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0-beta.1
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- dev-master
- dev-develop
- dev-craft3
This package is auto-updated.
Last update: 2024-12-16 19:43:47 UTC
README
Menu's & navigations made easy.
Requirements
This plugin works with Craft CMS 3.x, 4.x and 5.x
Installation
To install the plugin, follow these instructions.
cd /path/to/project
composer require studioespresso/craft-navigate
./craft install/plugin navigate
Templating
craft.navigate.raw
craft.navigate.raw
will give you an array of the items you added to the navigation, with children for each if you have those.
For each node you will have access to:
{% set nav = craft.navigate.raw('navHandle') %} {% for node in nav %} {{ node.name }} {{ node.url }} {{ node.classes }} {{ node.blank }} {{ node.children }} {% endfor %}
This gives you complete control over the HTML & CSS used to display your navigation.
Here's an example of how to show a navigation and it's possible children using a twig macro:
{% import _self as macros %} {% macro renderNode(node) %} {% import _self as macros %} <li class="{% if node.classes|length %}{{ node.classes }}{% endif %}"> <a href="{{ node.url }}" class="{% if node.active %}active{% endif %}" {% if node.blank %}target="_blank" rel="noopener"{% endif %}>{{ node.name }} </a> {% if node.children|length %} <ul> {% for child in node.children %} {{ macros.renderNode(child) }} {% endfor %} </ul> {% endif %} </li> {% endmacro %} <div> <ul> {% for node in nodes %} {{ macros.renderNode(node) }} {% endfor %} </ul> </div>
Headings
Since 2.3.0, headings can be added to make it easier to build larger navigations with mulitple sections or columns. To make full use of this you check check node.type == "heading"
and add the html you need in the condition.
These only work on multiple levels (eg: 3 headings on the top level, each with navigation items on deeper levels).
Configuration
You can create a file called navigate.php
in the config
directory (you can copy this one to start) to manage these settings in your code. The ones listed here are not available through the CP.
Disabling caching
Out of the box, the plugin will cache the querries it makes when devMode
is not enabled.
If you want to disable caching within the plugin entirely, you can do so by setting disableCaching
to true
in the plugin's configuration file. (see example here)
CSS class option list
Instead of the "Classes" field being a plain text field, you can also change it to a predefined dropdown with class that you want to make available for the user.
The nodeClasses
setting takes an array where that contains "Class to be applied" => "Label to be shown in the cp".
"nodeClasses" => [ '' => '---', 'nav nav-primary' => "Primary", 'nav nav-highlight' => 'Highlight' ]
Make sure to also include an empty option in case you don't want the the first item to be selected by default
Brought to you by Studio Espresso