Set $scripts variable for layout in AppController and SpecificController

I need to set google analytics script for layout on all pages, except one. So I call

$scripts = $this->Script->getUniversalScript();
$this->set(compact(‘scripts’));

in AppController beforeFilter

And

$scripts = $this->Script->getSpecificScript();
$this->set(compact(‘scripts’));

in SpecificController action, where I need specific google analytics script. I also have specific logic there so I cannot do it in AppController by taking controller name and action name. But it doesn´t work, because set() method in controller always takes value, which was first set (in AppController) and I need take last set (in SpecificController). Is there any way to make it? Thank you for any advice.

You want to append instead of overwrite?

you can use $this->_viewVars['scripts'] to read the value set in AppController beforeFilter and work with it

This kind of thing should be in your AppView class.

I forgot to mention, I´m using CakePHP 2.x which doesn´t support AppView

I tried to set universal scripts in beforeRender of AppController only if specific scripts are not set in $this->viewVars. But it still shows only universal scripts.