Skip to content

Instantly share code, notes, and snippets.

@ethanclevenger91
Last active November 30, 2016 19:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanclevenger91/16d34b9cc85b6e45b1c5 to your computer and use it in GitHub Desktop.
Save ethanclevenger91/16d34b9cc85b6e45b1c5 to your computer and use it in GitHub Desktop.
All in One Event Calendar - Adding filters + functions to Twig themes For more reading on uses of functions vs. filters in Twig: http://twig.sensiolabs.org/doc/advanced.html
function add_twig_functions_and_filters() {
global $ai1ec_front_controller;
$loader = $ai1ec_front_controller->return_registry(true)->get('theme.loader');
$twig = $loader->get_twig_instance(false, true);
function foo($date) {
if(mktime() > strtotime($date->__toString)) {
return true;
}
else return false;
}
$expired = new Twig_SimpleFunction('expired', 'foo');
$twig->addFunction($expired);
function bar($string) {
return $string.'ringding';
}
$filter = new Twig_SimpleFilter('mFilter', 'bar');
$twig->addFilter($filter);
}
add_action('init', 'add_twig_functions_and_filters');
{% if expired(event.get('start')) %}
<span>{{'Expired'|mFilter}}</span> //Will output 'Expiredringding'
{% endif %}
@christianvoigt
Copy link

Thank you very much, this is just what I was looking for! I was nearly giving up, after looking at the plugin code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment