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.