Hint: In the eZ Components Template component template operators will be called template functions (or so I've heard and read before). So in the future your name for this construct will be accurate. Until then create yourself a template operator ... it's fun!
Sébastien : An operator can only return values to put in a variable, can't it ? What I would like to do is to directly display the result (without an dirty echo in the operator class of course)
Hans : Thanks :-) But can you tell me how please ? ^^
I'm about to develop my first extension and was already able to implement a template fetch function prototype.
My search about template operators, template functions and template fetch functions just lead me to this article. As it's the only resource describing differences of the above (even the docs don't tell the difference), I just add my questions here.
What is the difference between template fetch functions and template operators? How does one know what's the best choice?
There is a logical difference first of all:
- template operator: a 'decorator' of the input it receives, or a simple operation
- fetch function: accesses info from db or external resource (eg. via webservice). It needs to be tied to a module, too - plain template function: more complex and powerful operations relating usually to the templating system rather than the content system
As for the differences in coding:
- there is a wizard that allows to create easily template operators, there is none for functions/fetch functions
- for fetch functions otoh the API is simpler, as you can register any php function you like. You will need to create a function_definition.php file in your module dir; take existing function_definition.php files as an example - template functions are defined via the $eZTemplateFunctionArray variable in the same eztemplateautoload.php file where template operators are defined
Principal Consultant International Business
Member of the Community Project Board
Pfft. Those wizards you mention are rubbish bit rott not to be relied upon.
They do -not- produce valid template operator php source code -nor- do they output even flexible or reusable template operator php source code (re: design pattern differences decipherable)
Fetch functions are the most practical to use overall for most of my kind of needs (based on your descriptions).