After upgrading from 6.x-2.1-beta2 to 6.x-2.1-beta3, the menu shows up but the js and css files are no longer being loaded. I am using the nice_menus_primary_links() function in my page.tpl.php template file of my theme. This was working fine in 6.x-2.1-beta2.

Cheers,

Antoine

Comments

jantoine’s picture

To clarify, my page.tpl.php template file has the following line:

<?php print theme('nice_menus_primary_links'); ?>

Cheers,

Antoine

add1sun’s picture

Status: Active » Postponed (maintainer needs more info)

Did you clear your cache? The JS and CSS got moved in the code and you need to clear your theme registry for it to work with the new one.

jantoine’s picture

Status: Postponed (maintainer needs more info) » Active

I ran this through the debugger and the code is being called, but it is still not showing up when the page is rendered. Is there a chance it is too late at this point to be calling drupal_add_js() and drupal_add_css()?

Cheers,

Antoine

jantoine’s picture

@add1sun,

Sorry, I did not see your comment prior to my last comment but yes, I have cleared all chaches via the admin_menu module.

Cheers,

Antoine

jantoine’s picture

@add1sun,

Indeed, my page.tpl.php template file is being called before the theme_nice_menus() function is called so the scripts are being added after the theme is rendered.

Cheers,

Antoine

add1sun’s picture

Hm, weird. I can't reproduce the problem locally. The CSS and JS appear fine for me, using default NM blocks and theme_nice_menus_primary_links(), with and without caching enabled, so I don't know. Are you overriding theme_nice_menus() in your template.php?

ucf713’s picture

I have the same issue since upgrading to to 6.x-2.1-beta3.

jantoine’s picture

Not sure if its relevant, but the theme I am using is a Zen sub-theme.

Cheers,

Antoine

jantoine’s picture

@add1sun,

I have not overridden the theme_nice_menus() function in my template.php file.

Cheers,

Antoine

ucf713’s picture

Went back to 6.x-2.1-beta2 for now until this issue can be narrowed down.

justindavis’s picture

I am having the same problem with my zen-based theme.

lukebrooker’s picture

I am having the same problem with my tao based theme.

The Code I am using is:

print theme_nice_menus_primary_links();

butler360’s picture

Same problem with theme that has no base theme.

EDIT: Maybe I wasn't having the same problem. My problem was that I still had the Nice Menus css overridden in the the global theme configuration. Still, it's something to check.

add1sun’s picture

OK, well I still can't reproduce this problem on my test sites, so this sucks. theme_nice_menus_primary_links() directly calls theme_nice_menus() in order to build the menu at all, so it can't be getting called after the theme is built. If the Nice Menu is displaying at all, then theme_nice_menus() has been invoked. There are only 2 things I can think of to cause the problem when using the theme function directly:

- Theme registry has not been rebuilt by clearing the Drupal cache.
- theme_nice_menus() is being overridden with the old code (which lacks the CS and JSS)

Is everyone who is experiencing this calling a theme function or are you using blocks? If you use both a function call and a block does one work and not the other? Please make sure you check the 2 points above, and for thoroughness, run update.php.

f2boot’s picture

same problem using fusion core, light fantastic and custom template

i am just using the theme function (same method than lukebrooker #12)

I checked all recommandations in #14, no better result

checking html output, i see
all js comes in a single file and does not include nice_menu.js (nor all the sukerfish needed)

and adding an "echo" on top of includes/common.inc/drupal_add_js
i can see that nice_menu.js is called after header is output (while all the other javascript are rendered before)

would js come to late for js preprocess ?

thanks

add1sun’s picture

Does anyone get this issue when using Garland?

add1sun’s picture

Hm, once I added a custom CSS file through the global theme config, I lost my JS and CSS. So, #13 looks like the lead. Is everyone/anyone having this problem using the custom path for CSS file?

EDIT: I only lose my CSS, the JS still works fine for me regardless.

pivica’s picture

I have the same problem. After some investigation I think that you can not just simply call theme_nice_menus_primary_links() (or some other nice_menus menu theme function) in custom template_preprocess_page function or custom page.tpl.php template file. Problem is that js/css files are included in http://api.drupal.org/api/function/template_preprocess_page/6 and this function will be called before custom template_preprocess_page and page.tpl - thats why we are missing nice_menus css/js files.

My solution is that in custom template_preprocess_page I do this

// Create nice menu primary menu.
$vars['primary_menu'] = theme('nice_menus_primary_links');

// Recreate css and scripts vars to add nice_menu css/js.
$vars['css'] = drupal_add_css();
$vars['styles'] = drupal_get_css();
$vars['scripts'] = drupal_get_js();

And then in custom page.tpl.php

<?php print $primary_menu; ?>

lukebrooker’s picture

Thanks pivica, That (#18) worked for me.

whayes’s picture

Thanks - that worked!

For us newbies:
I opened up my template.php file in my theme folder and added the lines indicated into phptemplate_preprocess_page function in that file.

Agileware’s picture

I can confirm that this affects garland also.

It will affect all themes because if you call your theme function from the page.tpl.php, which then calls drupal_add_js(), the js has already been added to the template so this new js is added too late (as pivica mentioned in #18).

I can confirm the work around in #18 works for me too.

If you are trying to reproduce this and can't maybe you have a nice menus block on the same page or something. If you do that block will add the required files and there will be no problem. Disable the blocks and you should see the problem.

The only real solution is to pull the drupal_add_js & drupal_add_css calls out of the theme functions and have them somewhere else, although there is no way of knowing if the theme is using these theme functions or not and it isn't ideal to just blindly load the files on every page.

One possibility for primary links & secondary links could be to have an check box options on the nice menus settings page to use nice menus for the primary and secondary links.
The module can then implement a nice_menus_preprocess_page function which checks those settings and if they are checked it does what the code snippet in #18 does.
Then people would not have to change any code to use nice menus for the primary and secondary links, just check a checkbox (provided their theme prints $primary_menu and/or $secondary_menu, otherwise they would have to add that).

This problem would still exist whenever people directly called these theme functions from their page.tpl.php though.
For these cases, include the snippet from #18 in the documentation so people know that's what needs to be done.

For the time being that code snippet should be added to the documentation anyway.

I haven't got time to make a patch for the above suggestion at this stage but it is a possible solution.

[EDIT] Also, I'm not using a custom css file.

add1sun’s picture

Yeah, sorry folks, I've been preoccupied the last few days. I'm going to have to revert the last change which moved them into the theme function and put them back in init. I'll get to that later today and do a new release.

Roze-1’s picture

Subscribe

add1sun’s picture

Status: Active » Fixed

OK, went ahead and did it now, while I'm here and thinking about it. Reverted the change and new Beta 4 is now out.

Agileware’s picture

Cool, that was quick. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

drupalfan2’s picture

Status: Closed (fixed) » Needs work

This solution is not working for me.

This is the way I am using Nice Menus:

- I am using the nice menus block and I activate one nice menu block in /admin/build/block in my menu region
- This is the way I am printing the nice menu in page.tpl.php (I print the block):

  <?php if ($nice_menu): ?>
    <?php print $nice_menu; ?>
  <?php endif; ?>

Nice menu works until I activate the CSS aggregation in /admin/settings/performance (Optimize CSS files = ON).

Above solution do not work.

PLEASE HELP! Thanx.

add1sun’s picture

Status: Needs work » Closed (fixed)

This issue is fixed and closed and is not about aggregation. If you are having other problems, then please open a new issue.