0

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?

6
  • Hi, I put the include_javascripts() call in my head section too, and I've already use the use_javascript_for_form() call later. This call is similar to use_javascript I think, and it must be supposed to work. I don't know how though. Commented Sep 2, 2010 at 17:04
  • Are you using it layer in the layout or the template? The template get's rendered before the layout, so in those cases it's not an issue. Commented Sep 2, 2010 at 17:15
  • Ah ok it's because I'm using it in my layout. But what about you? Isn't your head in your layout? Commented Sep 2, 2010 at 17:27
  • Yes...but I'm including a component in my layout which uses use_javascript, so I thought it would be pointless to call use_javascript twice, once in my head, the other in the component. Commented Sep 2, 2010 at 17:30
  • It's a helper + component. The purpose of this was to create components which know how to refresh themselves with an AJAX call. They register themselves with a mediator js object...that JS should be included with the component, otherwise it won't work. I happen to be including one such refreshable component in my layout.... Commented Sep 2, 2010 at 18:20

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.