Skip to content

Instantly share code, notes, and snippets.

View johndwells's full-sized avatar

John D Wells Jr johndwells

View GitHub Profile
@johndwells
johndwells / _macro-excerpt.html
Created August 6, 2014 16:25
A twig macro for returning an entry excerpt
{% macro excerpt(default, fallback, limit) %}
{% if default | length > 0 %}
{{ default }}
{% else %}
{% set fallbackRaw = fallback | striptags %}
{% set excerpt = (fallbackRaw | length > 200) ? fallbackRaw | slice(0, 200) ~ '...' : fallbackRaw %}
<p>{{ excerpt }}</p>
{% endif %}
{% endmacro %}
@johndwells
johndwells / getEntryLocaleUrls
Created September 30, 2014 15:19
Custom plugin to fetch entry locale URLs
/**
* Get all locale-specific URLs for a given entry.
*
* @param Craft\ElementCriteriaModel $entry
* @return Array
*/
public function getEntryLocaleUrls($entry)
{
// get all site locales
$localeIds = craft()->i18n->getSiteLocaleIds();
@johndwells
johndwells / Iterator.js
Last active August 29, 2015 14:13
Small utility class which takes an array and returns an Iterator.
var Iterator = function (collection, options) {
var version = 1.1,
defaults = {
infinite : false
};
if (options !== null && typeof options === 'object') for (var key in defaults)
if (options.hasOwnProperty(key)) defaults[key] = options[key];
@johndwells
johndwells / gist:5ee4db3e0d0501b97ca5
Created February 27, 2015 16:49
A layout-wide "pagination" module
{if layout:paginate_total_pages}
<div class="page">
<a
{if layout:paginate_previous_page}
class="page-previous" href="{layout:paginate_previous_page}"
{if:else}
class="page-previous disabled" href="#"
title="Previous Page">
{/if}
@johndwells
johndwells / gist:42faea67114da4fcf637
Created February 27, 2015 16:50
Setting layout pagination variables in a channel loop
{paginate}
{pagination_links}
{previous_page}{layout:set name="paginate_previous_page" value="{pagination_url}"}{/previous_page}
{next_page}{layout:set name="paginate_next_page" value="{pagination_url}"}{/next_page}
{layout:set name="paginate_current_page" value="{current_page}"}
{layout:set name="paginate_total_pages" value="{total_pages}"}
{/pagination_links}
{/paginate}
@johndwells
johndwells / gist:e1eefceea68ee0d3405a
Created April 17, 2015 09:55
Example of how to configure Minimee for Craft on a per-tag basis.
{#
To start with, all Minimee tags by default run off the settings
from the database (via it's plugin settings page), OR
from craft/config/minimee.php if you prefer to configure it via the filesystem.
Then you can override individual settings, on a per-tag basis,
by passing a hash (Twig's name for a key => value array). You can either
set this hash first and then pass it, or pass it at the time of the minimee tag call.
#}
@johndwells
johndwells / pi.myplugin.php
Created May 26, 2015 22:33
How to switch MSM sites mid-template render
/**
* Begin boilerplate plugin code ...
*
* $this->cache is set up in the __construct(), and is just a reference
* to a custom key as part of $this->EE->session->cache, e.g.
* $this->cache =& $this->EE->session->cache['myplugin'] = array();
*/
function msm_switch_site()
{
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# Change these settings to your own preference
@johndwells
johndwells / 0_reuse_code.js
Last active August 29, 2015 14:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@johndwells
johndwells / grid.scss
Last active August 29, 2015 14:26
An atomic, BEM-style variable/mixin suite for creating flexible, configurable grids.
/* ==========================================================================
The Grid
========================================================================== */
/**
* An atomic, BEM-style variable/mixin suite for creating flexible, configurable grids.
*
* All variables may be overwritten globally, or at runtime via mixin parameters.
*
* 1. Variables