I am learning cakephp in an autodidact manner and I am a complete newbie 🙂 I am creating a simple application. Some logic work so now I going to dive into designing views and layouts.
I read the docs and the tutorial but I could not find where to set the content of $script_for_layout.
Especially I want to set a $html->css to create link in pages to the stylesheet. I found out that I could do it in directly in the layout template but I would like to create the same link in all pages/views/layouts to the stylesheet so I hope there is a simple way, and avoid to do this in all layouts and/or controllers
I am learning cakephp in an autodidact manner and I am a complete newbie
Share
You can do this with the
JavascriptHelper. Load the helper via the controller’s$helpersarray.In the view code, the
falseparameter adds/js/my_script.jsto the set of scripts loaded by the$scripts_for_layoutvariable. To do the same thing for CSS, the key is the same$inlineparameter. Set that value to false and the CSS file will load in the head as well:Take a look at the documentation for general helper info and for the Javascript helper specifically.