Skip to content

Instantly share code, notes, and snippets.

View iainurquhart's full-sized avatar

Iain Urquhart iainurquhart

View GitHub Profile
@iainurquhart
iainurquhart / gist:9dc908b0a75b22e05f57
Last active August 29, 2015 14:11
facetedNav plugin example usage
{% 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 %}>
$customDbConfig = array(
'*' => array(
'tablePrefix' => 'craft',
),
'test1.foo.com' => array(
'server' => 'localhost',
'user' => 'test1user',
'password' => '',
@iainurquhart
iainurquhart / gist:fd35da453e2b07d5ff6d
Created December 1, 2014 23:45
batch filters in twig
{% for profileRow in entry.teamProfiles|batch(4) %}
<div class="row team_members_wrapper">
{% for profile in profileRow %}
<div class="col-sm-6 col-md-3">
<div class="team_member">
{% set photo = profile.photo.first() %}
{% if photo is not empty %}
<img src="{{photo.url}}" alt="{{ profile.personName }}">
{% endif %}
<h5>{{ profile.personName }}</h5>
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->limit = 100;
$criteria->sectionId = 4;
$entries = craft()->elements->findElements($criteria);
foreach($entries as $entry)
{
...

Templating in EE vs. Craft

Lots of people have asked, so here are a few common tasks you might do in your templates, as they would be written in ExpressionEngine vs. Craft.

Table of Contents

  1. Comments
  2. Conditionals
  3. Loops
@iainurquhart
iainurquhart / gist:11385028
Created April 28, 2014 21:48
active and active_parent classes to navigation
{% set topEntry = craft.entries.depth(1).slug('about-us').first() %}
{% set parents = entry.getAncestors() %}
<ul>
{% nav item in topEntry.getDescendants() %}
{% set isParent = false %}
{% for parentItems in parents %}
{% if parentItems.id == item.id %}
@iainurquhart
iainurquhart / gist:11363859
Last active August 29, 2015 14:00
Auto expanding navigation (Only siblings of parents displayed)
{% set topEntry = craft.entries.depth(1).slug('about-us').first() %}
{% set parents = entry.getAncestors() %}
<ul>
{% nav item in topEntry.getDescendants() %}
{% set showChildren = false %}
{% for parentItems in parents %}
{% if parentItems.id == item.id or entry.id == item.id %}
# Description:
# Shows an image the specified Goonie somewhere.
#
# Dependencies:
# None
#
# Configuration:
# None
#
# Commands:
@iainurquhart
iainurquhart / gist:8481777
Created January 17, 2014 21:18
example of image widget using P&T assets, you'll need to update the ACT id for outputting the image thumb, relevant to your install.
<table class="mainTable entry_widget_notop" border="0" cellspacing="0" cellpadding="0" data-index="0">
<tbody>
<tr>
<td style="width: 100px;">
<?php if($options['image_id']):?>
<img src="/?ACT=40&file_id=<?=$options['image_id']?>&size=100x100&hash=1361909881">
<?php endif ?>
<p><a href="#" class="thumbnail_trigger">Add File</a></p>
{exp:channel:entries channel="some_pages" limit="1"}
{exp:taxonomy:set_node
tree_id="2"
entry_id="{entry_id}"
}
<p>You are here:
{exp:taxonomy:breadcrumbs}
{if here}