Last active
August 29, 2015 14:11
-
-
Save iainurquhart/9dc908b0a75b22e05f57 to your computer and use it in GitHub Desktop.
facetedNav plugin example usage
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
{% set navItems = craft.facetedNav.getNav() %} | |
<nav class="sidebar"> | |
{% for catGroup in navItems.categoryGroups %} | |
<fieldset> | |
<legend>{{ catGroup.name }}</legend> | |
<ul> | |
{% for cat in attribute(navItems.categories, catGroup.handle) %} | |
<li{% if cat.active %} class="active-item"{% endif %}> | |
<a href="{{ cat.url.add }}" class="add">{{ cat.title}}</a> | |
{% if cat.active %} <a href="{{ cat.url.remove }}" class="remove" title="Remove this filter">×</a> {% endif %} | |
</li> | |
{% endfor %} | |
</ul> | |
</fieldset> | |
{% endfor %} | |
</nav> | |
<article class="content"> | |
<h2 class="page-title">Browse our catalogue</h2> | |
{% if navItems.activeCategories|length %} | |
<nav class="filter-crumbs"> | |
<h3>Browsing items filed under:</h3> | |
{% set relatedTo = ['and'] %} | |
{# list our current active categories #} | |
{% for category in navItems.activeCategories %} | |
<a href="{{ category.url.remove }}" title="Remove this filter">{{ category.title }} <span>×</span></a> | |
{# while we're here, set our params for main entries call #} | |
{% set catIds = craft.categories.groupId(category.attributes.groupId).slug( category.attributes.slug ).ids() %} | |
{% for id in catIds %} | |
{% set relatedTo = relatedTo|merge([id]) %} | |
{% endfor %} | |
{% endfor %} | |
{% set entries = craft.entries.section('catalogue').relatedTo(relatedTo) %} | |
</nav> | |
{% else %} | |
{% set entries = craft.entries.section('catalogue') %} | |
{% endif %} | |
{% if entries | length %} | |
{% for entry in entries %} | |
<div class="item"> | |
<h2>{{ entry.title }}</h2> | |
<p class="meta"> | |
Type: {% for plantType in entry.plantclassification %}[{{ plantType.title }}] {% endfor %}<br /> | |
Soil: {% for soilType in entry.soilClassification %}[{{ soilType.title }}] {% endfor %}<br /> | |
Sun: {% for sunType in entry.lightClassification %}[{{ sunType.title }}] {% endfor %} | |
</p> | |
</div> | |
{% endfor %} | |
{% else %} | |
<p class="no-results">Sorry, not much here yet :{(</p> | |
{% endif %} | |
</article> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment