If knowledge is power, then sharing knowledge is ultimate powertrip
Latest Updates
You are here: Home >> Frameworks >> Cakephp >> cakephp include javascript file in view

cakephp include javascript file in view

You probably know that if you have $scripts_for_layout in your site’s layout, then you can do a Cakephp include javascript file in view. For example, if you’d like to include ‘myScript.js’ from some view you would add the following code: $javascript->link(‘myScript’, false);

Basically the second param (false), will tell CakePHP not to include the file in-line, but rather where the $scripts_for_layout is located.

A less known feature is that you can do the same for your CSS files. So, if you need to include some style that is specific to a given view, add something like this to your view file:

$html->css(‘myViewCss’, ‘stylesheet’, array(“media”=>”all” ), false);

Again, you simply need to specify a ‘false’ parameter. This will tell CakePHP to include the CSS file where the $scripts_for_layout variable is located (which should be in the ).

About Jawed Shamshedi

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Scroll To Top