Last active
February 28, 2017 16:53
-
-
Save jnowland/99b5fa5d4dba564fc64e to your computer and use it in GitHub Desktop.
Craft Snippets
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
{# Shows all categories in the news group #} | |
{% set categories = craft.categories.group('news') %} | |
<ul> | |
{% nav category in categories %} | |
<li> | |
<a title="{{ category.title }}" href="{{ category.url }}">{{ category.title }}</a> | |
{# Output a nested <ul> if this category has any children #} | |
{% ifchildren %} | |
<ul>{% children %}</ul> | |
{% endifchildren %} | |
</li> | |
{% endnav %} | |
</ul> |
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
{# Spits out all entries with the category 'events' in 'news' channel #} | |
{% set eventCategory = craft.categories.find({group: 'news', slug: 'events', limit: 1}) %} | |
{% set eventEntries = craft.entries.section('news').relatedTo(eventCategory).limit(5).find() %} | |
{% for entry in eventEntries %} | |
{{ entry.title }} | |
{% endfor %} |
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
{# If you need to use handle bar tempaltes that use the same template as twig you can use the raw tags to get around this! #} | |
<figure class="Gallery js-Gallery" | |
data-cycle-fx=scrollHorz | |
data-cycle-prev="#prev" | |
data-cycle-next="#next" | |
data-cycle-caption=".js-GalleryCount" | |
{% raw %}data-cycle-caption-template="{{slideNum}} of {{slideCount}}"{% endraw %} | |
></div> |
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
{% if 'events' in entry.newsCategories | group('slug') | keys %} | |
{# Has events as a category assigned to it. #} | |
{% endif %} |
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 up the thumb manipulations #} | |
{% | |
set thumbnail = { | |
mode: 'crop', | |
width: 63, | |
height: 63, | |
quality: 85, | |
position: 'center-center' | |
} | |
%} | |
{# Set the Source #} | |
{% set imagePlaceholderVar = entry.ImageAssetField[0] %} | |
<img src="{{ imagePlaceholderVar.getUrl(thumbnail) }}" width="{{ imagePlaceholderVar.getWidth(thumbnail) }}" height="{{ imagePlaceholderVar.getHeight(thumbnail) }}" class="u-mediaBlockPreview Thumbnail--rounded margin--right8" /> |
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
{# Paged Pagination that correctly shows the first and last page number only if they are not already in the pagination #} | |
<ul class="Pagination"> | |
{% if paginate.prevUrl %} | |
<li class="Pagination-item Pagination-prev"> | |
<a href="{{ paginate.prevUrl }}"> | |
<span class="icon ChevronLeftGreen"><</span> Prev | |
</a> | |
</li> | |
{% endif %} | |
{% for page, url in paginate.getPrevUrls(1) %} | |
{# Always show the "first page" url if the pagiation offset is out of range #} | |
{% if loop.first and paginate.firstUrl != url %} | |
<li class="Pagination-item"> | |
<a href="{{ paginate.firstUrl }}" class="Pagination-number">1</a> | |
<span class="Pagination-hellips">…</span> | |
</li> | |
{% endif %} | |
<li class="Pagination-item"> | |
<a href="{{ url }}" class="Pagination-number">{{ page }}</a> | |
</li> | |
{% endfor %} | |
{# Always output the current page #} | |
<li class="Pagination-item is-current"> | |
<span class="Pagination-number">{{ paginate.currentPage }}</span> | |
</li> | |
{% for page, url in paginate.getNextUrls(1) %} | |
<li class="Pagination-item"> | |
<a href="{{ url }}" class="Pagination-number">{{ page }}</a> | |
</li> | |
{# Don't show the "total page" url if it's in the pagiation already #} | |
{% if loop.last and paginate.lastUrl != url %} | |
<li class="Pagination-item"> | |
<span class="Pagination-hellips">…</span> | |
<a href="{{ paginate.lastUrl }}" class="Pagination-number">{{paginate.totalPages}}</a> | |
</li> | |
{% endif %} | |
{% endfor %} | |
{% if paginate.nextUrl %} | |
<li class="Pagination-item Pagination-next"> | |
<a href="{{ paginate.nextUrl }}"> | |
Next <span class="icon ChevronRightGreen">></span> | |
</a> | |
</li> | |
{% endif %} | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment