Skip to content

Instantly share code, notes, and snippets.

View dustinwalker's full-sized avatar

Dustin Walker dustinwalker

View GitHub Profile
<?php
/**
* area plugin for Craft CMS
*
* @author DW
* @copyright Copyright (c) 2017 DW
* @link www.url.com
* @package Area
* @since 1.0.0
*/
@dustinwalker
dustinwalker / secondary_nav_craftcms.twig
Created February 18, 2014 15:59
Secondary navigation sample
{#
# SECTION_NAME is name of section to generate secondary navigation for
# parent, childernPages, child can be any name you choose.
#}
{% set parent = craft.entries.section('SECTION_NAME').slug(craft.request.getSegment(1)).first %}
{% set childrenPages = parent.getDescendants(1) %}
<ul>
{% for child in childrenPages %}
@dustinwalker
dustinwalker / events_listing_craft.twig
Created February 18, 2014 15:58
List events in CraftCMS
{#
# SECTION_NAME is the name of the section for events
# allEvents, futureEvents, event can be anything
# Not sure where I got this sample from
#}
{% set allEvents = craft.entries.section('SECTION_NAME').limit(3).find() %}
{% set futureEvents = [] %}
{% for event in allEvents %}
@dustinwalker
dustinwalker / summary_craft.twig
Created February 18, 2014 15:58
Truncate field and add ellipse at end
{#
# FIELD.NAME is name of field.
#}
{{ FIELD.NAME|length > 155 ? FIELD.NAME|slice(0, 155)|striptags ~ ' ...' : FIELD.NAME }}
@dustinwalker
dustinwalker / active_class_craft.twig
Created February 18, 2014 15:57
Add active class to current page or if page is child of current section
{% if FIELDNAME.id == entry.id or FIELDNAME.isDescendantOf(entry) %} class="active"{% endif %}
@dustinwalker
dustinwalker / list_categories_and_entries_craft.twig
Created February 18, 2014 15:56
Find tags in given tag group, list tags and entries under each tag
{#
# FIELD_NAME is name of field
# sampleCategories, sampleCategory, category, entry, entries can be anything
#}
{% set sampleCategories = craft.tags.set('FIELD_NAME') %}
<ul>
{% for sampleCategory in sampleCategories %}
{% set category = craft.tags.search('name:'~sampleCategory.name).first() %}
{% if category %}