Last active
May 31, 2018 11:02
-
-
Save certainlyakey/b8d2dbea7569f8248e7f to your computer and use it in GitHub Desktop.
Craft CMS - display categories related to an entry macro
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
{# usage: {{ siteMacros.related_categories( entry, true, 'rubrics', 'rubric-list', 'Рубрики:', '?news=true' ) }} #} | |
{# in main layout: {% import '_partials/macros' as siteMacros %} #} | |
{% macro related_categories(entryModel, isSection=false, catGroupName='categories', className='categories', headingText='', appendToURL='') %} | |
{% set categories = craft.categories.group(catGroupName).relatedTo(entryModel) %} | |
{% if categories | length %} | |
{% if isSection %} | |
<section class="{{ className }}"> | |
<h1>{{headingText}}</h1> | |
{% endif %} | |
<ul{{ (isSection ? '' : ' class="' ~ className ~ '"')|raw }}> | |
{% for category in categories %} | |
<li><a href="{{ category.url }}{{appendToURL}}">{{ category.title }}</a></li> | |
{% endfor %} | |
</ul> | |
{% if isSection %} | |
</section> | |
{% endif %} | |
{% endif %} | |
{% endmacro %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment