Skip to content

Instantly share code, notes, and snippets.

@keithmancuso
Last active August 29, 2015 13:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithmancuso/9065506 to your computer and use it in GitHub Desktop.
Save keithmancuso/9065506 to your computer and use it in GitHub Desktop.
Options for CraftCMS Menus
{#
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