Module-based variable manipulation
This recipe will outline an alternative method to variable manipulation performed at the module level rather than at the theme level. This provides the advantage of being theme-agnostic, that is, the modifications made will be made available or applied to all themes which is particularly useful if a site uses more than one theme.
To demonstrate this approach, we will be adding a list of classes to the node template based on the taxonomy terms associated with the node in question.
Getting ready
We will be using the mysite module created earlier in this book as an example module to hold our odds and ends. Since we are going to demonstrate injecting classes based on the taxonomy terms, a sample node and associated terms will need to be created.
How to do it...
First up, we will be adding a preprocess function to the mysite module.
Navigate to the mysite module's folder in
sites/all/modules
.Open the
mysite.module
file in an editor.Create a
mysite_preprocess_node...