Skillbooker
Login Register

Cakephp


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')); 


Gabriel Kolbe
Posted on: 2016-06-01 Please login/register to leave comments