php - How to include helpers in smarty? -
id use static functions helpers in smarty template. im using ko3 , kohana-module-smarty - https://github.com/mranchovy/kohana-module-smarty/ question how autoload helper , use in template, ie:
app/class/url.php
class url {
function test () {
return 'test';
}
}
views/index.tpl
{$url.test}
you should able pass url
variable, $url
, , access within view {$url->test()}
. i'm not sure if able access static functions url::test()
though.
if you're using helper in same views, can create new controller binds variable in view:
<?php // application/classes/controller/site.php class controller_site extends controller_template { public $template = 'smarty:my_template'; public function before() { $this->template->set_global('url_helper', new url); } } ?>
then extend in other controllers:
<?php // application/classes/controller/welcome.php class controller_welcome extends controller_site { public function action_index() { $this->template->content = 'yada, yada, yada...'; } }
and access within views:
{* application/views/my_template.tpl *} <p>this {$url_helper->test()}.</p> <p>{$content}</p>
Comments
Post a Comment