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...

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...

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

Popular posts from this blog

CS5 Adobe Media Encoder: Encode failed because the source duration is nil.

cf_sql_integer vs cf_sql_bigint vs cf_sql_int??

localhost/joomla15/administrator doesnt work - Joomla! Forum - community, help and support