eZ Community » Forums » Developer » Creating a function within a tpl file

Creating a function within a tpl file

Creating a function within a tpl file

Monday 28 December 2009 6:17:47 pm - 1 reply

Hi, I currently have a template file which I am using to do multiple fetchs and display the elements of each fetch for the user. What I need to do is add some line of code that would be used in each of the loops I have but wanted to ask if there was a way to include the repeated code in a function (preferably inside the same tpl file) and then return the results.


Monday 28 December 2009 10:36:44 pm

The correct way to do it: create a template operator. It is about the only php code there is a RAD-generator for in the admin interface, and half a bazillion template operator extensions to take as examples.

The hackish way: separate your "function" code in a separate template, and use the {include uri='design:myfunction.tpl' vari1=$v1 var2=$v2} operator as if it was a function call. To get the value back in a variable, you will have to define said variable before the inclusion of the function-template (or use appropriately variable scopes, but it might be hard)


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from