By extexan on
Hi all,
How can I add a class to in a module (not in a theme)? It's my module that determines the conditions for adding classes - and my theme that will show or hide elements based on those classes.
TIA.
Hi all,
How can I add a class to in a module (not in a theme)? It's my module that determines the conditions for adding classes - and my theme that will show or hide elements based on those classes.
TIA.
Comments
You module can implement
You module can implement hook_preprocess_page(), set variables that represent the body id and class(es). Drupal already sets $body_classes which you could append to or override totally. Your theme will then need to use the variables as part of the body tag, example
Is that Drupal 6, or 7 ?
@nevits, thanks for that. Is that the Drupal 7 way? - coz I'm using 6.
I looked in Drupal API and didn't find hook_preprocessor_page. I found all manner of template_preprocess_page and phptemplate_preprocess_page. None with "preprocessOR", as you typed in your post - so I guessed that was just a type-o and it really should be just "preprocess". But those are all dealing with themes, not modules, right?
Is there really no way to add a body class from within a module?
It's never too late to have a happy childhood. ;-)
Sorry type on my part (I
Sorry type on my part (I corrected the post), modules can implement hook_preprocces_page. If your module was called mymodule, you would implement mymodule_preprocess_page.
How to find the variables
How to find the variables that represent the body id and class(es)?
Lets say, i'd like to style the node/2, node/3, etc... how would I identify unique body id or classes for each of the node?
Thanks
Similar to YourThemeName_preprocessing_page in a theme
I know this is a little late but I didn't see an example for Drupal 6.
Adding a class or classes to the body of a page from a module. Please note that you could use either $vars or $variables based on the function argument. In this example, I used $variables and also note it is passed by reference.
"It is a damn poor day when you don't learn something!" - Mr. Jones, teacher
Thnx, GS. Helpful
Thnx, GS. Helpful code.
Kieran
hook_preprocess is the correct one! :)
Here is the list of hooks that your module could implement,
and below, the link to the hook to pre-process theme variables from within a module.
Hope it helps!!
--
Federico