ezsystems/ezpublish — pull request #291 by ballinette (2012-02-22 19:24:24+00:00)
Title: Adding ezpevent notifications before and after template processing.

This pull request adds 2 ezpevent notifications during the template processing :
* template/pre_processing
* template/post_processing

These event notifications enable to hook PHP code just before or just after the template execution.

Example usage :

site.ini :

[Event]
Listeners[]=template/pre_processing@ezkTemplateHook::preProcess

class ezkTemplateHook :

public static function preProcess( &$tpl, $resourceData )
{
// Fetch variable from current node and set template variables :
$node = $tpl->variable( 'node' );
$testFieldsByLocation = self::getTestFieldsByLocation( ezpContentLocation::fromNode( $node ), $resourceData );
foreach( $testFieldsByLocation as $key=>$value )
{
$tpl->setVariable( $key, $value );
}
}

private static function getTestFieldsByLocation( ezpContentLocation $location, $resourceData )
{
// @TODO return an associative Array with values fetched using the API, depending on location and resource Data
}

Then variables can be used directly within the template's code without using the ugly templating language to do business processing.