[PHPTAL] callback?
Kornel Lesiński
kornel at aardvarkmedia.co.uk
Fri Jun 18 15:56:23 CEST 2010
On 18-06-2010 at 14:46:13 GRolf <gerolf at pictureparking.com> wrote:
> let's say I have a query that will fetch employees from a table. every
> row has a field "department_id".
>
> when looping through this array in my template, is there a way to call a
> "callback" function that will fetch the department's name from an other
> table?
PHPTAL automatically calls methods in TAL expressions. If you use ORM it
should be quite simple, e.g. if you have Employee object that has
getDepartment() method that returns Department object:
<li tal:repeat="employee employees"
tal:content="employee/getDepartment/name"/>
Alternatively you can call PHP functions using php: prefix in expressions:
<li tal:repeat="employee_row employees_array">
<tal:block tal:define="department
php:get_department_row(employee_row['department_id'])"
tal:content="department/name"/>
-- regards, Kornel
More information about the PHPTAL
mailing list