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



64.2k
Accepted
answer
edited Nov '15

well according to this : https://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Router.html

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



4.4k

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



10.2k

UI guys hate this, FYI.



10.2k

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). https://docs.phalconphp.com/en/latest/reference/assets.html

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