ez.no / ezpublish / documentation / development / kernel / custom template operators
These documentation pages are no longer maintained. Please visit the new documentation site.
eztemplatephpoperator allows for built-in php functions to be added as operators to the templating system. This is a brief explanation of what I have figured out about this system. There are currently a number of limitations but I'm sure this functionallity will be extended in the future.
If you want to use any PHP function as an operator, then read this page: Template operator
New template operators can be added easily by overiding the template.ini file. As an example we'd like to include base64 encoding as an operator. This is done with the following changes in template.ini
[PHP] # A list with php functions and their equivelant template operator names # Giving the operators a different name from the PHP functions # are recommended, that way you ensure that all operators follow # the same naming guidelines. It also means that you can change the # php function later on without doing template changes. PHPOperatorList[] PHPOperatorList[upcase]=strtoupper PHPOperatorList[downcase]=strtolower PHPOperatorList[reverse]=strrev PHPOperatorList[nl2br]=nl2br PHPOperatorList[urlencode]=urlencode PHPOperatorList[encodestring]=base64_encode PHPOperatorList[decodestring]=base64_decode
You can see from the example that the two lines for base64 encoding and decoding were appended to this section. Cache was deleted and with the operator in place the string was encoded.
Tip: You'll notice I used encodestring and decodestring instead of the actual name of the function used. This allows me to be able to change the ini later should I choose another method of encoding without having to change template files.
To use the new operator in your templates just add
{text you want to modify|new_ezpublish_operator}
to your templates
Example
{$node.name|upcasefirst}
I discovered this by trying to add a random templates operator. Unfortunately I was not able to accomplish that task using this method. This was because it is only possible to use this feature with php functions that take a single parameter.
You must use the operator in the method described above
{upcasefirst($node.name)} - does not work.
Comments
Calling any PHP function (also user defined ones)
Gunnstein Lye
Tuesday 20 April 2004 7:32:57 pm
See the link I have added at the top of the page, which describes a clean way to call PHP code from a template.
Solution Found
Francisco Felix
Friday 25 July 2003 11:47:43 pm
I will implement one function for every external funcionality I need and I will call it as a custom operator template, this will reduce the security risk associated with including custom code by the designers (a possibility with Marks approach).
Expanding posibilities
Francisco Felix
Friday 25 July 2003 10:26:26 pm
For example making and compiling PHP with a function that calls a poll from the poll system (apart from EZPublish) would allow us to use this function and pass the poll we want as a parameter:
{newest|new_ezpublish_poll_operator}
The function would receive the "newest" parameter or an integer for a specific poll, then the function would return the html that renders the poll.
Of course recompiling PHP is a big disadvantage, but it seems possible.
What i am looking for is how to insert php code in a template in order to call funcionality provided by third party programs. I inserted php code directly in a template and it come as is in the html code.
Any help will be appreciated.
Fantastic !
Esben Maaløe
Monday 21 July 2003 11:20:15 pm