Using $scripts_for_layout in CakePHP

In CakePHP, most times you might bump into a situation where you need to add scripts to the section of your view but you are not able to do it since your section is in your main layout. It’s possible to add javascript and css to the section of your template, by using the $scripts_for_layout variable in CakePHP (just had to dig a bit into the docs).
To use this just echo the var $scripts_for_layout in your main layout’s section. Then when required to link to a javascript file in the section from a view just use the javascript helper with the second argument set to false.
$javascript->link(”jquery”,false);