开发者

how to link javascript to $scripts_for_layout while in an element

I am currently wor开发者_如何学Pythonking 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?


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.


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.


This should do the job:

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

Maybe you just forgot the echo?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜