Best way to call on a helper from a template? - Joomla! Forum - community, help and support
i haven't found definitive answer this. following mvc conventions , have view template file want use helper function. example, if have entity called "course" have course view , helper called "course.php" in helpers folder.
it seems can load helper view.html.php file using...
...use function in view.html.php , assign result layout. call helper functions within template can pass template-specific parameters. if use method in layout file, , try call function helper cannot located.
should use require instead this...
if explain the steps use implementing helper in mvc component great.
it seems can load helper view.html.php file using...
code: select all
jview::loadhelper('course');
...use function in view.html.php , assign result layout. call helper functions within template can pass template-specific parameters. if use method in layout file, , try call function helper cannot located.
should use require instead this...
code: select all
require_once(jpath_component.ds.'helpers'.ds.'view.php');
if explain the steps use implementing helper in mvc component great.
i think found own answer...
for both methods added helper view.html.php contains function myfunction(), , added code top of view.html.php file...
option 1
you can access helper function inside tmpl file calling function...
option 2
you can access helper in view.html.php file itself, , use conditional rules decide when it, example...
and in tmpl file...
think use option 1 mainly. option 2 more work guess cleaner templates. see other people doing. please share methods here!
for both methods added helper view.html.php contains function myfunction(), , added code top of view.html.php file...
code: select all
// add course helper
jview::loadhelper('course');
option 1
you can access helper function inside tmpl file calling function...
code: select all
<?php echo myfunction($parameter); ?>
option 2
you can access helper in view.html.php file itself, , use conditional rules decide when it, example...
code: select all
// use function if in course layout
if (jrequest::getvar('layout') == 'course') {
// parameter use in helper function
$parameter = jrequest::getvar('courseid', 'default');
// use helper function
$result = myfunction($parameter);
// assign helper function result view
$this->assignref('result', $result);
}
and in tmpl file...
code: select all
<?php echo $this->result; ?>
think use option 1 mainly. option 2 more work guess cleaner templates. see other people doing. please share methods here!
Comments
Post a Comment