Closed phoenixg closed 11 years ago
I’ve not used the PHP implementation of Mustache (just the JavaScript version), but if you’re using a base handler class, maybe set some site-wide variables in there, and then add to them in your extending handler classes? Something like this:
abstract class BaseHandler {
protected $templateVariables;
public function __construct() {
$this->templateVariables = array(
'base_url' => BASE_URL
);
}
}
class TestHandler extends BaseHandler {
public function get() {
$tpl = $this->mustache->loadTemplate('test');
$this->templateVariables['foo'] = 'bar';
echo $tpl->render($this->templateVariables);
}
}
Let me know how that works for you. I’m closing this issue as it’s more to do with Mustache and not ToroPHP itself.
Hi, this works, I use this method now, thanks!
I have dozens of xHandler, so pass the base_url every time seems not elegant way.