Last active
August 29, 2015 13:56
-
-
Save keithmancuso/9065506 to your computer and use it in GitHub Desktop.
Options for CraftCMS Menus
This file contains 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
{# | |
normal craft structure menu | |
------------- | |
works well in enough most of the time but limited in that it combines the content sturctures with the menu structures into a single section, making more complex navigations more complicated. | |
#} | |
{% set pages = craft.entries.section('pages') %} | |
{% nav page in pages %} | |
<li> | |
<a href="{{ page.url }}">{{ page.title }}</a> | |
{% ifchildren %} | |
<ul> | |
{% children %} | |
</ul> | |
{% endifchildren %} | |
</li> | |
{% endnav %} | |
{# | |
A more advanced option allowing navigation across multiple sections. | |
------------------ | |
Create a separete "Menu" section and give it two fields. The user builds their menu anyway they want by adding entries to "menu" structure and linking to any other entry in the system. | |
- relatedEntry - Entries field allowing you to select any other entry | |
- customURL - text field for custom url input | |
#} | |
{% set menu = craft.entries.section('menu') %} | |
{% nav link in menu %} | |
<li> | |
{% if link.relatedEntry|length %} | |
<a href="{{ link.relatedEntry[0].url }}">{{ link.title }}</a> | |
{% else %} | |
<a href="{{ link.customURL }}">{{ link.title }}</a> | |
{% endif %} | |
{% ifchildren %} | |
<ul> | |
{% children %} | |
</ul> | |
{% endifchildren %} | |
</li> | |
{% endnav %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment