3

I'm trying to disable the LabJS module from running on certain pages by following the maintainers instructions at Compatibility issue with Slickgrid.

This is what I have, so far. I tried putting it directly in the page and my themes template.php with the theme's name appended to the function name, but neither work.

/**
 * Disable LabJS on certain pages
 */
function versatile_hook_init() {    
  if (current_path() == "private/members/search") {
    define('LABJS_DISABLE', TRUE);
  }
}

Can you help pointing me in the right direction?

  • 2
    Try versatile_init() instead of versatile_hook_init(). :-) Also, remember hook_init() doesn't get called on cached pages. – Jan Tomka Aug 11 '11 at 11:21
  • And if you need to check page path, try hook_boot. The modules aren't loaded in hook_boot yet, beware. – Capi Etheriel Aug 11 '11 at 18:31
7

hook_init() must be implemented in a custom module. In your example, the function mymodule_init() would go into a file named mymodule.module in a custom module named mymodule. You would also supply a simple mymodule.info file and put both files in the sites/sitename/modules/mymodule directory.

The custom module must be enabled like any other. Also, when creating a hook implementation, it is usually necessary to clear the cache for Drupal to recognize it. Finally, note that mymodule needs to be a unique name different from other modules or themes.

As a minor usage point, current_path() returns the current URL which may not be the current alias (e.g., node/5). Using drupal_get_path_alias() is recommended to always return a friendly alias.

  • mymodule_init() instead of mymodule_hook_init(). ;-) – Jan Tomka Aug 11 '11 at 11:23
  • Thanks for the advice, I'll give it a try after I've had some sleep. Good to know about the page caching. Also the page URL's for this page are coming from a Panel, but I assume drupal_get_path_alias() will still work. – Bryan Casler Aug 11 '11 at 11:40
  • This is what I've got so far, but it's not working labjs_disabler.info and labjs_disabler.module – Bryan Casler Aug 15 '11 at 21:09
  • I forgot a "/" in the labjs_disabler.module, here is the corrected one labjs_disabler.module – Bryan Casler Aug 15 '11 at 21:16
  • 1
    The '/' is not needed. Your problem is the name of your hook function. You have labjs_disabler_hook_init, and it should be labjs_disabler_init. 'hook' is a placeholder for the module name. – keithm Aug 16 '11 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.