Cakephp

How to individually display css and javascript files for individual views in Cakephp

Here is How to individually display css and javascript files for individual views in Cakephp. Function in the layout and set it in the view


How to individually display css and javascript files for individual views in Cakephp

In the default.ctp layout.

  if(isset($cssIncludes)){
    foreach($cssIncludes as $css){
       echo $this->Html->css($css);
    }
}

if(isset($jsIncludes)){
    foreach($jsIncludes as $js){
       echo $this->Html->script($js);
    }
}

In the action of the view in the controller..

$this->set('cssIncludes',array('my_css')); // this will link to /css/my_css.css in function
$this->set('jsIncludes',array('my_jsfile')); 

Published: 1st June 2016 by Gabriel Kolbe

Adverts