Skip to content

Instantly share code, notes, and snippets.

View croxton's full-sized avatar
💭
Up to my elbows, as usual

Mark Croxton croxton

💭
Up to my elbows, as usual
View GitHub Profile
@croxton
croxton / gist:3436786
Created August 23, 2012 13:48
Stash + ifelse + playa
{exp:stash:set_value name="tc" value="{exp:playa:total_children}" parse="inward" type="snippet"}
{exp:ifelse parse="inward"}
{if tc > 10}
...
{if:else}
....
{/if}
{/exp:ifelse}
@croxton
croxton / gist:3315420
Created August 10, 2012 16:36
Dynamic Stash embeds using context
{!-- file at stash_templates/my_context/my_template.html --}
{!-- standard embed syntax --}
{stash:embed name="my_context:my_template"}
{!-- shortcut embed syntax --}
{stash:embed:my_context:my_template}
{!-- set embed name dynamically from a Stash variable --}
{stash:embed name="{stash:layout}"}
@croxton
croxton / gist:3227974
Created August 1, 2012 15:44
Multiple languages in matrix field rows overriding default title/body/summary fields in an entry
{!-- handle language fields --}
{services_languages}
{!-- language switcher --}
{exp:stash:append name="page_languages" type="snippet"}
<option value="/{exp:cat2:url_title category_id='{language}'}{structure:page:uri}{exp:stash:get name='tab' type='snippet'}"{if "{global:lang}" == "{exp:cat2:url_title category_id='{language}'}"} selected="selected"{/if}>{exp:cat2:name category_id="{language}"} ({exp:cat2:url_title category_id="{language}"})</option>
{/exp:stash:append}
{!-- capture language fields --}
{exp:stash:set name="page_title_{exp:cat2:url_title category_id='{language}'}" type="snippet" parse="inward"}
@croxton
croxton / Apache tuning
Created June 28, 2012 11:20
Apache config for VPS with 2Gb Ram running nginx as a reverse proxy for static files
My Apache config for a VPS with 2Gb Ram and the following:
* CentOS
* cPanel
* Apache 2.x (MPM Prefork)
* Nginx as a reverse proxy for static files (Nginx Admin cPanel plugin)
* APC, or eAccelerator for opcode caching
* One or multiple ExpressionEngine websites
min spare servers 2
@croxton
croxton / Apache tuning
Created June 28, 2012 11:10
Apache config for VPS with 2Gb Ram running nginx as a reverse proxy for static files
My Apache config for a VPS with 2Gb Ram and the following:
* CentOS
* cPanel
* nginx as a reverse proxy for static files
* APC opcode caching for PHP
min spare servers 2
max spare servers 5
@croxton
croxton / Loader.php
Created June 13, 2012 16:38
Rewrite and extend the Loader class on the fly, to make some useful properties public again
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Rewrite and extend the Loader class on the fly, to make some useful properties public again
*
* @package CodeIgniter
* @author Mark Croxton ([email protected])
* @copyright Copyright (c) 2012 Hallmark Design
* @link http://hallmark-design.co.uk
*/
@croxton
croxton / Workaround for CI 2.1.0 protect identifiers bug
Created June 13, 2012 12:03
CodeIgniter 2.1.0 alias escaping problems
CI 2.1-stable Active Record tries to escape db tables, fields and aliases with backticks, however it can trip up on queries such as...
$this->CI->db->where("last_activity < {$expire}");
... which is an example actually used in the Session class in 2.1-stable.
So out of the box you will get an SQL error when using database sessions.
Of course that should probably be rewritten:
$this->CI->db->where("last_activity <", $expire);
@croxton
croxton / gist:2413194
Created April 18, 2012 12:15 — forked from electricputty/gist:2412497
blank stash
Sometimes this value is blank
{exp:stash:get_list name='result_data'}{if '{cf_catentry_date}' != ''}{cf_catentry_date}{/if}{/exp:stash:get_list}
// find in mod.stash.php:
if ( $this->not_empty($matches[1]) || $matches[1] === '0')
{
$stash_vars[substr($key, 6)] = preg_replace('/'.LD.'stash:[a-zA-Z0-9\-_]+'.RD.'(.*)'.LD.'\/stash:[a-zA-Z0-9\-_]+'.RD.'/Usi', '', $matches[1]);
}
@croxton
croxton / Stash paginated results listing
Created April 16, 2012 09:53
Stash paginated results listing
{!-- build result rows --}
{exp:stash:set parse_tags="yes"}
{stash:results_rows}
{exp:channel:entries
channel="my_channel"
limit="10"
paginate="bottom"
dynamic="no"
}
@croxton
croxton / gist:2157654
Created March 22, 2012 10:49
Passing a tag as a parameter - best practice
Put parameters on separate lines, and be consistent in the use of quotes: double quotes for params on the main tag, single quotes for params in the tag passed as a parameter:
{exp:stash:set_value
name="ref"
type="snippet"
output="no"
value="{exp:stash:get name='ref_{entry_id}' type='snippet'}"
parse="inward"
}