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!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 30 2025 21:47:41
Script start
Timing: Jan 30 2025 21:47:41
Module start 'layout'
Timing: Jan 30 2025 21:47:41
Module start 'content'
Timing: Jan 30 2025 21:47:41
Module end 'content'
Timing: Jan 30 2025 21:47:41
Script end

Main resources:

Total runtime0.0244 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0049 588.1328151.2109
Module start 'layout' 0.00490.0045 739.3438220.6953
Module start 'content' 0.00940.0134 960.03911,001.9922
Module end 'content' 0.02280.0016 1,962.031333.9766
Script end 0.0244  1,996.0078 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002711.2417140.0002
Check MTime0.00114.4034140.0001
Mysql Total
Database connection0.00062.591110.0006
Mysqli_queries0.002711.143130.0009
Looping result0.00000.053710.0000
Template Total0.00124.810.0012
Template load0.00093.577710.0009
Template processing0.00031.170110.0003
Override
Cache load0.00062.472010.0006
General
dbfile0.00135.232980.0002
String conversion0.00000.036140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs