I can't find this addressed elsewhere, so I thought I'd have a stab at it...
I'm adding Javascript using drupal_add_js inline for a block in a module I'm making. In bluemarine/push button this Javascript loads and can execute just fine. In chameleon/marvin the Javascript isn't being loaded. I'm not sure if this is a drupal_get_js() problem or something else, but the themes that work are just printing $scripts while the ones that don't work rely on that function.
If I create a page in the site using the same code that creates the block, the page's Javascript loads and executes just fine in chameleon/marvin. It just seems to be the code defined in the module for the block. Maybe it's just a fluke, but I don't have the time to try and reproduce it with different code atm.
Comment | File | Size | Author |
---|---|---|---|
#6 | load-blocks_1.patch | 2.89 KB | kkaefer |
#5 | load-blocks_0.patch | 1.7 KB | kkaefer |
#3 | load-blocks.patch | 1.63 KB | kkaefer |
Comments
Comment #1
kkaefer CreditAttribution: kkaefer commentedFirst of all, this is not a problem with Drupal but with your very own code - at least you are altering themes.
The
$scripts
variable is calculated by phpTemplate before the actual template is loaded. That means, you can add as many JavaScript code in your theme - it won’t be reflected in this variable. To solve this problem, replace$scripts
withdrupal_get_js()
.Comment #2
kkaefer CreditAttribution: kkaefer commentedThis is actually an issue with Drupal.
Comment #3
kkaefer CreditAttribution: kkaefer commentedThe problem was: JavaScript that is added in a block is not present in the
head
in plain PHP (non-phpTemplate) themes. The reason for this is that the blocks are fetched when they are to be inserted in the page, not before. Butdrupal_get_js()
has already been called in the page header. Thus, the added JavaScript file (or other JavaScript code) is not in the header because it is added afterwards.The patch moves the
theme_blocks()
call before thedrupal_get_js()
call to ensure that JavaScript that is added by blocks is added to the page header.Comment #4
Dries CreditAttribution: Dries commentedCode looks good but I'd love to see this documented with a comment or two. It is tempted to move this calls back down -- a comment would prevent that.
Comment #5
kkaefer CreditAttribution: kkaefer commentedAdded a description
Comment #6
kkaefer CreditAttribution: kkaefer commentedDid the same thing in theme_page() as the issue also occured there.
Comment #7
kkaefer CreditAttribution: kkaefer commentedComment #8
drummCommitted to HEAD.
Comment #9
(not verified) CreditAttribution: commented