开发者

How do I call use_javascript after include_javascripts has been called?

开发者 https://www.devze.com 2023-01-15 02:19 出处:网络
In my layout, I\'m calling include_javascripts() in my <head></head> section. Later on in my layout, I\'m calling a component which makes use of use_javascript(), but, unfortunately, the j

In my layout, I'm calling include_javascripts() in my <head></head> section. Later on in my layout, I'm calling a component which makes use of use_javascript(), but, unfortunately, the javascript has been output, so this request falls on deaf ears.

I can think of a few approaches:

  1. Put the call to `include_javascripts()` at the bottom.

    At the moment I can't do this, because I'm using a CMS on top of symfony which uses a lot of inline javascript.

  2. Override the include_javascript helper, or create a new one, which adds doesn't add anything, but adds it adds to a queue that a filter will take care of after rendering the page.

    This is sort of like the common filter which was removed from 1.2. Obviously, they don't seem to like this approach.

Are there any other alternati开发者_如何学编程ves?


The use_javascript function simply adds the specified script to a collection, which is output by the include_javascripts function.

In order to have inline javascript in your code, you will need to use tags, since the use_javascript is pointless unless include_javascripts is called afterwards.

If you do not want to deal with filenames and such, you could always use sfConfig::get('sf_root_dir') . js/filename.js to grab your file.

0

精彩评论

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

关注公众号