Optimizing using hook_preprocess()
This recipe will demonstrate using the hook_preprocess()
function in a module. We will be using it to seemingly export settings from one template file to another by making information from the node template available to the page template file. In this example, we will be adding the author's roles into the class list of the BODY
tag as well as part of the content of the node.
Getting ready
We will be using the myzen theme created earlier in this book as the example theme in this recipe. It is also assumed that the node.tpl.php
and page.tpl.php
files exist in myzen's templates
folder.
Just as with the previous recipe where we added our preprocess
function to a module, we will be adding our function here into the mysite module.
How to do it...
First, let us add our preprocess
function to the mysite module.
Navigate to the mysite module's folder within
sites/all/modules
.Open the
mysite.module
file in an editor.Create a
mysite_preprocess()
function in this file as...