Forums / Developer / Creating a function within a tpl file

"Please Note:
  • At the specific request of Ibexa we are changing this projects name to "Exponential" or "Exponential (CMS)" effective as of August, 11th 2025.
  • This project is not associated with the original eZ Publish software or its original developer, eZ Systems or Ibexa".

Creating a function within a tpl file

Author Message

Kedar Deshpande

Monday 28 December 2009 9:17:47 am

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.

thanks.

Gaetano Giunta

Monday 28 December 2009 1: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)

Principal Consultant International Business
Member of the Community Project Board