robwilkerson Messages: 18 Registered: January 2010
Junior Member
So this seems like a trivial task that should be available in several ways, yet I can't seem to find any information. I suppose I'm searching for the wrong terms, but that's what brings me here. I'm hoping someone can help.
I need to write a bit of Javascript to the head of my layout from a page. Since Symfony may be able to provide a better way of doing so that I can think of right now, I'll just explain what I'm trying to do.
I have a page that displays N widgets. Only the page knows how many widgets it has to render. I need to get that number to a bit of javascript so that it can make certain adjustments if there is only one widget to be rendered. My intent was to write a global variable to the layout that could be accessed by a JS source file. Unfortunately, I can't find a way to write a block of JS (not a source file) to the head section of my layout.
I thought that the javascript_tag() helper might offer that capability, but it appears not. What's the best way of accomplishing this?