Monday, August 31, 2009

Second argument in javascript's link method (CakePHP)

To create a link to javascript files, we can use 'link' method.
For example, if I type echo $javascript->link('tiny_mce/tiny_mce.js',false);

The second argument is 'false'. It means the script link will be displayed in the html's head section.
If it is 'true', the link will be displayed in html's body section.

Well, there's actually more story to how CakePHP choose where to put the link.
Actually, if second argument is 'false', the link will be displayed in $scripts_for_layout section, and if it's 'true', it will be displayed in $content_for_layout.

Both $scripts_for_layout and $content_for_layout is written inside the layout file.
If you create your own layout, you should find the file inside app/views/layouts folder.
If you use the default layout, the file is cake/libs/view/layouts/default.ctp

You will see that the $scripts_for_layout is written inside the head section, and $content_for_layout is written inside the body section.

No comments: