Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

how insert js code in end body

Hi! I can insert different js.js in here < / body> but how insert <scrypt> bla-bla-bla </scrypt> </ body> depending from the action controller or simple controller. I know there are ways to code injection through the "elements", but it is necessary to implement JavaScript code is depending on the controller used. One controller wants to show one code to another need another. hint about the true idea please

edited Nov '15

well according to this :

there are :

public getModuleName ()
public getControllerName ()
public getActionName ()

so inside your layout you can do

if($this->router->getControllerName () === 'cars') {
    echo "<script type="text/javascript" src=""whatver.js></script>";

or if you have different views just put the js there.

hope i understood you correctly


Thank you!!! All right. It is that what i needed.


UI guys hate this, FYI.


Sorry, not a very helpful comment. If you want to dynamically insert JS, either include it in the view that is being loaded in the controller (my favorite way) or use Phalcon's resource combiner (still haven't gotten it to work).

Use views(volt) and just render this code in volt..... not from controller, wtf.