views:

67

answers:

1

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 alternatives?

A: 

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.

Jon