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:3810681
Created October 1, 2012 10:08
Better Workflow > Assets integration
In ft.assets.php add this to the top of the pre_process function:
/**
* Pre Process
*/
function pre_process()
{
// -------------------------------------------
// Get the exp_assets_entries rows
// -------------------------------------------
@croxton
croxton / header--patch.php
Last active May 31, 2016 20:43
If your clients use IE, do them and yourself a favour and disable the compatibility button in the Control Panel by editing ./system/expressionengine/views/_shared/header.php Why? Because many popular fieldtypes break the publish screen with the compatibility button pressed.
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
@croxton
croxton / gist:1790604
Created February 10, 2012 16:23
Switchee devot:ee
{exp:switchee variable="{segment_1}/{segment_2}/{segment_3}" parse="inward"}
{case value = "//"}
{!-- s1, s2 and s3 are empty - Show home page --}
{embed="site/_home"}
{/case}
{case value="#^products/\S+/\S+$#"}
{!-- s1 is 'products', s2 and s3 are not empty - Show single products --}
{embed="site/_product"}
@croxton
croxton / gist:1835200
Created February 15, 2012 11:34
Stash no results placeholder trickery (untested)
{!-- The URL structure is like this /wiki/{category}/{url_title}/
If I fill in random characters for the {url_title}, {no_results} should be TRUE.
I've verified through the Template debugger that it does indeed return "No results", but the redirect @L91 to the 404 does not work. Is there a problem with the parse order, or is it something with Switchee/Stash?
Thanks!
---------------------------------------------------------------------------------------- --}
{exp:stash:set name="wiki_navigation" type="snippet" parse="inward"}
@croxton
croxton / gist:1931841
Created February 28, 2012 10:45
JSONP with ExpressionEngine - core hack
Currently you're stuck if you need to return JSONP from a EE template, because appending callback=? to your uri will make EE throw an Invalid Get Date error. In case you didn't know, JSONP is a great way to do cross-domain AJAX and let your EE website function as a web service.
To get round this restriction in EE 2.4 amend line 116 of /system/expressionengine/core/EE_Input.php from:
elseif (preg_match("#(;|\?|exec\s*\(|system\s*\(|passthru\s*\(|cmd\s*\(|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})#i", $val))
To:
elseif (preg_match("#(;|\?\S+|exec\s*\(|system\s*\(|passthru\s*\(|cmd\s*\(|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})#i", $val))
This still gives you protection against the use of ? in query strings to pass arguments, but allows you to append a ? to the very end of your query only - which is all we need.
@croxton
croxton / gist:2135739
Created March 20, 2012 13:44
Assets custom field for Taxonomy
This will add an 'Assets' fieldtype to Taxonomy.
Caveats:
* only images will be visible in the Assets sheets
* only one image can be selected
* shows all file upload locations that the user's member group can access
* stores the actual image url NOT the Assets path eg {filedir_1}my_image.jpg.
Iain - you might want to implement Assets path {filedir} parsing for your Taxonomy module
tags and then store the Assets url instead (which is in files[0].path). Then users can move
the image in Assets and it won't break the link...
@croxton
croxton / gist:2135481
Created March 20, 2012 13:21
Stash embeds
I have a new tag {exp:stash:embed} which allows you to include Stash template files and store
in the database. Files can be fully or partially parsed when read before saving (set), OR
saved and then parsed on retrieval (get). Stash variables can be accessed in the Stash
template files as {stash:variable} and of course all the usual {global_variables} work as
expected.
An example:
{exp:stash:embed
name="news_listing"
@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"
}
@croxton
croxton / gist:1582667
Created January 9, 2012 12:03
Taxonomy and Stash - primary navigation
In the viewModel:
{exp:stash:set name="nav_main" parse_tags="yes" save="yes" refresh="60" replace="no" scope="site"}
{exp:taxonomy:nav tree_id="1" depth="1" ul_css_id="my-id"}
<a href="{node_url}"{stash:nocache}{if "{exp:stash:get name='segment_1' type='global'}" == "{/stash:nocache}{node_url}{stash:nocache}"} class="active"{/if}{/stash:nocache}>{node_title}</a>
{/exp:taxonomy:nav}
{/exp:stash:set}
(I'm assuming Taxonomy {node_url} is something like 'my_page' NOT 'www.mysite/my_page', so that we can compae it to {segment_1}- if it produces something else adjust the conditional above accordingly)
@croxton
croxton / gist:2036269
Created March 14, 2012 12:54
{exp:taxonomy:nav template_path="{segment_1}/{segment_2}"}
// --------------------------------------------------------------------
/**
* Returns the first node_id for a given template path
* @param string template_path
* @return int node_id,
* but if no rows returned, false
*/
function get_node_id_from_template_path($template_path)
{