Reputation: 17764
Is it possible to set a template variable in a helper?
Ultimately what I'm trying to do is have a helper add in code to the header of the layout, for use with javascript and such.
Ways I can think of that I'd prefer not to use:
Any thoughts?
Update 2012-02-20: As cake as been updated more recently I've tried to include answers to Cake 1.2 as well as Cake 2. Thanks to Adam and mark for their recommendations
Upvotes: 2
Views: 1888
Reputation: 17764
I discovered you can use the class registry to grab it, so I made this function in my helper:
/**
* Access to the view for special operatoins
*/
protected function getView() {
return ClassRegistry::getObject('view');
}
Update 2013-02-20:
I wrote the above for Cake 1.2, Adam (in the comment below) suggested using $this->_View->viewVars['var']
for Cake 2.3 which looks good, but I don't have a way to test.
Upvotes: 4