Adding a variable to all node templates
In this recipe, we will be adding a variable to be made available in all node template files. For this example, the new variable will contain a disclaimer which we will be displaying at the bottom of all nodes.
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 a node.tpl.php
file exists in myzen's templates
folder as per recipes in earlier chapters. If not, this file will need to be imported from the Zen base-theme or a new one will need to be created.
How to do it...
A new variable can be made available to node template files by introducing it via the appropriate preprocess function as follows:
Navigate to the myzen folder at
sites/all/themes/myzen
.Open the file
template.php
in an editor.As mentioned in the introduction to this chapter, this file will have a number of commonly used preprocess functions in skeleton form. These are usually commented out.
Look for the function...