Custom Template Operators

Author Message

Jough Dempsey

Tuesday 04 December 2007 1:24:34 pm

I used the RAD tool in the admin to generate a stub for a custom template operator, but now I'm unsure as to what needs to change, or how this class is used by eZ publish to return a value(s).

I imagine that the methods included in the stub file are required, but they're also (as far as I can tell) completely undocumented. The namedParameterList() seems the most obvious, but are there any other parameters of the modify() method that I need to worry about?

Can anyone point me to custom template operator documentation (on ez.no or elsewhere).

I found this wiki page: http://ezpedia.org/wiki/en/ez/template_operators

but it also doesn't say where to place the template operator file, where or how to include it (unless you're using the autoload), or how it all works.

Jough Dempsey
Senior Developer
D U O : C O N S U L T I N G
Web Content Management Experts
http://www.duoconsulting.com

Paul Leclercq

Tuesday 04 December 2007 3:05:34 pm

Hiya Jough,

Try this page:
http://ez.no/fr/ezpublish/documentation/development/extensions/template_operator

It is a good simple exemple for hello world.

Basically, an operator is a function which can be used in your template:

You will find a list of the pre-built operators here:
http://ez.no/doc/ez_publish/technical_manual/3_10/reference/template_operators

To use your operator in the template once created you simply need to do something like:
{def $my_variable = my_operator('my_parameter1', 'my_parameter2')}

You can then display you result
like this:
{$my_variable} or {$my_variable|attribute(show)} if you are returning an array

As explained in the above hello world exemple: you will need to create your operator in the
/extension folder
you will need to tell the system that you have an operator in the
extension/myextension/settings/site.ini.append

And place your extension in the folder:
extension/myextension/autoloads

Once you have created your extension don't forget to activate it by going to the administration interface -> setup -> extensions -> tick and activate -> clear cache

Let us know how you get on!

Jough Dempsey

Monday 10 December 2007 1:38:48 pm

Thank you for your reply, Paul. It helped a lot, although I found that I could do the simple search that I needed to with the built-in fetch template functions (after a fashion).

Jough Dempsey
Senior Developer
D U O : C O N S U L T I N G
Web Content Management Experts
http://www.duoconsulting.com

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 18 2025 19:09:33
Script start
Timing: Jan 18 2025 19:09:33
Module start 'layout'
Timing: Jan 18 2025 19:09:33
Module start 'content'
Timing: Jan 18 2025 19:09:34
Module end 'content'
Timing: Jan 18 2025 19:09:34
Script end

Main resources:

Total runtime1.1199 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0043 587.9141152.6250
Module start 'layout' 0.00430.0021 740.539139.4453
Module start 'content' 0.00631.1119 779.9844537.9609
Module end 'content' 1.11830.0016 1,317.945312.1641
Script end 1.1199  1,330.1094 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.3208160.0002
Check MTime0.00140.1292160.0001
Mysql Total
Database connection0.00050.042810.0005
Mysqli_queries1.065795.1565570.0187
Looping result0.00060.0575550.0000
Template Total1.089097.220.5445
Template load0.00180.161420.0009
Template processing1.087297.073520.5436
Template load and register function0.00020.017010.0002
states
state_id_array0.00140.125610.0014
state_identifier_array0.00240.217620.0012
Override
Cache load0.00150.1326320.0000
Sytem overhead
Fetch class attribute can translate value0.00080.073720.0004
Fetch class attribute name0.00130.114340.0003
XML
Image XML parsing0.00220.197220.0011
class_abstraction
Instantiating content class attribute0.00000.000740.0000
General
dbfile0.00230.2019150.0002
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 21
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs