Skip to content

Instantly share code, notes, and snippets.

@richardsongo
richardsongo / gist:6ee1de84033f54c9ba3d
Last active August 29, 2015 14:21
Conditional statement if an entries relation field is empty?
{% if entry.fieldHandle |length %}
{{ entry.fieldHandle}}
{% else %}
{{ global.fieldHandle}}
{% endif %}
How can I conditionally display content if its a specific section?
{% if entry.section.handle == 'lettings' %}
<div class="menu-links">
<a href="{{ url('about') }}" {% if craft.request.firstSegment == 'about' %}class="active"{% endif %}>About</a>
<a href="{{ url('services') }}" {% if craft.request.firstSegment == 'services' %}class="active"{% endif %}>Services</a>
<a href="{{ url('work') }}" {% if craft.request.firstSegment == 'work' %}class="active"{% endif %}>Work</a>
<a href="{{ url('news') }}" {% if craft.request.firstSegment == 'news' %}class="active"{% endif %}>News</a></a>
<a href="{{ url('resources') }}" {% if craft.request.firstSegment == 'resources' %}class="active"{% endif %}>Resources</a>
<a href="{{ url('contact') }}" {% if craft.request.firstSegment == 'contact' %}class="active"{% endif %}>Contact</a>
</div>
{# Paginate the News entries in groups of 4 #}
{% paginate craft.entries.section('news').relatedTo(category).limit(4) as newsEntries %}
{# Loop through this page's News entries #}
{% for newsEntry in newsEntries %}
{% set entryCategory = newsEntry.categories.first() %}
{# Figure out where this entry should link to #}
{# Paginate the News entries in groups of 4 #}
{% paginate craft.entries.section('news').relatedTo(category).limit(4) as newsEntries %}
{# Loop through this page's News entries #}
{% for newsEntry in newsEntries %}
{% set entryCategory = newsEntry.categories.first() %}
{# Figure out where this entry should link to #}