Forums / Developer / Custom template operator

Custom template operator

Author Message

Sao Tavi

Monday 21 March 2011 8:02:13 pm

I am having problems implementing a custom template operator. The only hint I got was:

"Yes - use the $eZTemplateFunctionArray variable in a eztemplateautoload.php file in the autoloads dir of an extension"

So I looked for examples on how to do that and I've done "my own":

<?
class my_temp_op
{
function my_temp_op()
{
}
function operatorList()
{
return array( 'my_op');
}
function namedParameterPerOperator()
{
return true;
}
function namedParameterList()
{
return array( 'my_op' => array( 'type' => 'string',
'required' => true,
'default' => '' )
);

}
function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters )
{
switch ( $operatorName )
{
case 'my_op':
{
$operatorValue = 'outputtext';
} break;
}
}
}
?>

And I expect when {using my_op('something')} in a template to get 'outputtext'. The problem is that this is not happening.

Here is the definition of the templateoperator:

<?
$eZTemplateOperatorArray = array();
$eZTemplateOperatorArray[] = array( 'script' => 'extesion/myext/autoloads/my_op_file.php',
'class' => 'my_temp_op',
'operator_names' => array( 'my_op') );
?>

Any help, please? Also, a tutorial about this would be appreciated... I do not understand how one wants to grow a community without giving proper documentation about the object that the community is gathered around.

Peter Keung

Monday 21 March 2011 10:52:58 pm

This is a good article to check out: http://share.ez.no/learn/ez-publish/an-introduction-to-developing-ez-publish-extensions/%28page%29/10

Do you have a file extension/myext/settings/site.ini.append.php in your extension with contents similar to the example in the above link?

Did you regenerate the autoloads file? php bin/php/ezpgenerateautoloads -e -p

Perhaps it is a typo on this line?

$eZTemplateOperatorArray[] = array( 'script' => 'extension/myext/autoloads/my_op_file.php',

http://www.mugo.ca
Mugo Web, eZ Partner in Vancouver, Canada

Sao Tavi

Tuesday 22 March 2011 3:37:08 am

Thank you. That was a typo, you were right. I was pretty tired last night but I really wanted to be able to start doing the real work today.

No luck still... The worst is that I cannot see any error message in the logs, something like: "file not found", or "parsing error" or anything. I'm just working blindly on a undocumented class just by looking at examples. The eztemplateautoload.php file should be good now. This is the new class definition (with changes made according to the link received, thank for the link)

Later edit: Good, i works! I never checked site.ini.append.php, but it seems there was a typo. I can get working now. Thank you for your help!