tags:

views:

133

answers:

4

I am currently working on a application that will be implementing user customizable widgets on each users dashboard. The user is able to add and remove widgets at will. Each widget is contained within its own element and some have JavaScript files with need to be loaded individually.

The current issue I'm having is if i try and link a JavaScript into the $scripts_for_layout using the following code in an element, nothing will happen.

<?php $javascript->link('widgets/blog',false); ?>

After looking around a bit if found a ticket in the cakephp bug tracker that explains why and a commenter even suggested a workaround that can get around this:

<?php echo join("\n\t", $this->__scripts); ?>

I tried using this but it doesn't seem to work. Does anyone know any other workaround for this issue or even have suggestion on how to do this better?

A: 

I'm not quite sure why $javascript->link(…, false) shouldn't work in an Element, but you could try this:

$this->addScript($javascript->link('path/to/script'));

This should work in a View. In a Layout, as noted in the bug you're linking to, this won't work, since the header scripts will already be output by the time the element is rendered.

deceze
A: 

I don't think you can use $javascript->link from an element when that element is being included from the layout file. Somebody correct me if I am wrong.

Abba Bryant
A: 

This should do the job:

<?php echo $javascript->link('widgets/blog',false); ?>

Maybe you just forgot the echo?

Gian Basagre
A: 

After doing research i found that this is not possible at the moment due to how cakephp is constructed.

Shard