-
Notifications
You must be signed in to change notification settings - Fork 20
Mustash plugin development
Mustash plugins are classes that extend the Mustash_plugin
abstract class. Plugin class names must start with Stash_
and end with _pi
, and the file should be named accordingly.
Plugin files should be placed in ./system/expressionengine/third_party/mustash/plugins/
(string) The name of the plugin.
(string) The plugin version.
(array) An array of hooks that the plugin acts on, and, optionally, the markers available to each hook. Can be either an indexed array or, if there are markers, a multidimensional array.
The @all
hook can be used to create a reference to all hooks defined for the plugin. Rules attached to the @all
hook will be triggered by any of the other hook events.
protected $hooks = array(
'@all' => array(
'marker_1',
'marker_2',
'marker_3',
),
'hook_1' => array(
'marker_1',
'marker_2',
'marker_3',
),
'hook_2' => array(
'marker_1',
'marker_2',
'marker_3',
),
);
protected $hooks = array('hook_1', 'hook_2', 'hook_3');
Should return an array of group ids and group names associated with the object that the plugin is modelling. Always return an empty array if the plugin does not operate on groups.
With the exception of @all
, each hook defined in the $hooks array must have an associated method implementing that hook.
This method triggers any rules associated with the plugin hook (identified by $hook), which are assigned to the passed group ID ($group_id), and parses any markers in the pattern defined for each rule.
(string) The hook that was triggered - required.
(integer) The parent group ID of the content that was edited. Pass FALSE
or 0
if the group is unknown or not relevant - optional.
(array) An associative array of markers and their values - optional.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Mustash cache-breaking plugin
*
* @package Mustash
* @author Mark Croxton
*/
class Stash_my_plugin_pi extends Mustash_plugin {
/**
* Name
*
* @var string
* @access public
*/
public $name = 'My Plugin';
/**
* Version
*
* @var string
* @access public
*/
public $version = '1.0.0';
/**
* Extension hook priority
*
* @var integer
* @access public
*/
public $priority = '10';
/**
* Extension hooks and associated markers
*
* @var array
* @access protected
*/
protected $hooks = array(
'hook_1' => array(
'marker_1'
)
);
/**
* Constructor
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Set groups for this object
*
* @access protected
* @return array
*/
protected function set_groups()
{
return array(
'1' => 'Group 1',
'2' => 'Group 2',
'3' => 'Group 3',
);
}
/*
================================================================
Hooks
================================================================
*/
/**
* Hook: hook_1
*
* @access public
* @param integer $group_id the group ID of item that was edited
* @return void
*/
public function hook_1($group_id)
{
// prep marker data
$markers = array(
'marker_1' => $group_id
);
// flush cache
$this->flush_cache(__FUNCTION__, $group_id, $markers);
}
}
Getting started
Using Stash
Using Mustash
- Mustash
- Installing Mustash
- Managing variables
- Managing bundles
- Cache-breaking rules
- Mustash plugins
- Mustash Varnish plugin
- Mustash plugin development
- Mustash API
Template design patterns
Tag reference
- {exp:stash:set}
- {exp:stash:get}
- {exp:stash:block}
- {exp:stash:set_value}
- {exp:stash:append}
- {exp:stash:append_value}
- {exp:stash:prepend}
- {exp:stash:prepend_value}
- {exp:stash:copy}
- {exp:stash:context}
- {exp:stash:is_empty}
- {exp:stash:not_empty}
- {exp:stash:set_list}
- {exp:stash:get_list}
- {exp:stash:append_list}
- {exp:stash:prepend_list}
- {exp:stash:split_list}
- {exp:stash:join_lists}
- {exp:stash:list_count}
- {exp:stash:unset}
- {exp:stash:flush_cache}
- {exp:stash:bundle}
- {stash:embed}
- {exp:stash:extend}
- {exp:stash:parse}
- {exp:stash:cache}
- {exp:stash:static}
- {exp:stash:finish}
- {exp:stash:not_found}
- Short tag syntax
- Using Stash methods in your own add-ons