Tuesday, February 4, 2014

Using blocks for script and CSS files

Trying to figure this out. I understand the blocks as outlined in the book

 

http://book.cakephp.org/2.0/en/views.html#using-blocks-for-script-and-css-files

 

Simply add the scripts you need specific for that page and it gets places in the layout where you "fetch".

 

Problem is when your requesting that page via ajax there is no layout.

 

LAYOUT.CTP :

<……..>

<css scripts>

 

<?php echo $this->fetch('content');?>

 

 

<?php echo $this->fetch('js');?>

 

<…..>

 

 

If you have anything js related / jQuery dependant and you have the code in the view it gets placed in fetch('content') before the scripts are loaded resulting in $ is not defined / not a function when loading the view via ajax.

 

What is the work around for these circumstances? Am I missing something?

 

Thanks,

Dave

No comments: