Version 10, last updated by Torkil Johnsen at 26 Feb 00:23 UTC
This wiki has been updated for version 0.7-alpha4
1. Template helpers usage
Nooku framework provides two ways to access a method defined in a template helper:
- by using KTemplateHelper::factory()
- by loading the helper in templates with @helper alias
1.1 Helper factory
You must call KTemplateHelper::factory() and pass an identifier to the helper method. The following code will call the format() method in ComFooTemplateHelperDate class.
KTemplateHelper::factory('com://admin/foo.template.helper.date')->format();
If you need to access a helper defined in the framework or in com_default, you can use this short form:
KTemplateHelper::factory('listbox')->enabled();
In the example above, the factory will call the enabled method in class KTemplateHelperListbox (or ComDefaultTemplateHelperListbox if defined).
1.2 Loading helper in view templates
When accessing helper from view templates, you should use the helper alias, as in the following examples:
<?= @helper('com://admin/foo.template.helper.listbox.enabled', array('name' => 'published')) ?>
<?= @helper('listbox.enabled', array('name' => 'published')) ?>
Those instructions will perform a call to the enabled() method of classes ComFooTemplateHelperListbox and KTemplateHelperListbox respectively, and pass an array as input parameter.
Unlike the factory approach, this way of calling a helper has some magic in it. When using the @helper alias, the helper is passed automatically in input:
- the model state when in BROWSE views
- the row data when in READ views