Skip to main content
Topic: Make templates infinitely pluggable (Read 2031 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Make templates infinitely pluggable

If we changed all of the template_*() calls to call this function instead, it will allow every plugin and theme author to add before/after every call.

Code: [Select]
define('TEMPLATE_EVENT_CALL_BREAK', true);

/**
 * Call a  template
 * Should always be used to allow events
 *
 * @param string $name
 */
function template_call($name)
{
$args = func_get_args();
$name = array_shift($args);

if (empty($name))
{
throw new \InvalidArgumentException('$name cannot be empty');
}

$return = null;
$hook = 'template_' . $name;

call_integration_hook($hook . '__pre', $args);

$do_execute = call_integration_hook($hook . '__execute', $args);
if (empty($do_execute))
{
$return = call_user_func_array($name, $args);
}

call_integration_hook($hook . '__post', $args);

return $return;
}

If you're watching my View branch, it is AbstractTemplate::call()

Something to do for 1.1 without breaking everything. If you don't change the call to template_call() it doesn't break anything, you just don't get the hooks.
Last Edit: February 19, 2014, 01:42:06 pm by groundup
Come work with me at Promenade Group