Clips are your best bet, as @jfrej offers, pointing you to a forum topic where clips are discussed.
Under normal circumstances, each controller is associated with a folder in which all its views are located, and in this case you want to include some PHP + Javascript content that is common to all actions in the controller at the end of the layout (this is how they refer, not the templates) .
I would override the CController::afterRender() method to capture the content for your clip; allows you to call your clip controller_content :
afterRender(string $view, string &$output) $this->beginClip('controller_content'); // output here any content you want to capture into your clip // eg renderPartial, echo, etc. ... $this->endClip(); parent::afterRender($view, $output); }
Then in your layout you will display your clip after everything that is always there, for example:
// register your CSSs // output $content variable // register Javascript ... <?= $this->clips['controller_content'] ?>
Of course, there are different ways to generate your clip content. Here I tried the CController::afterRender() method, but you can also use filters, behavior, or any other approach that best suits your needs.
source share