I have a custom field called site_category that I am using in a few different content types. The field site_category is an entity reference to a content type which has only one field defined: Title. For the purposes of this example, I have three instances of that content: Things, Widgets, Places
I have another content type called content that has a number of fields including site_category
(Think of this like taxonomy, but using content types rather than terms)
I would like to add in the site_category field to my page.tpl.php so that it not only displays the title of the page, it also displays the site category that it is related to.
So, as an example, if I had a "Super Duper Widget De-Duper" that fell under the widgets category...
example URI:
.com/widgets/super-duper-widget-deduper
Page would render (styled of course):
Header
**Widgets**
**Super Duper Widget De-Duper**
Content
Footer
I have found a number of similar posts here on stackoverflow like this one: Access custom node field in page.tpl.php However, it dosen't work and I don't know what I am doing wrong. There is a lot of php code provided, but I don't know where to put said php code because it is never really referenced.
I have added the output from the Devel module. It appears that the field is being loaded as it is "there." Shouldn't I be able to access it?
I have added the following code with a reference to the field that is displaying in Devel:
if (isset($variables['id'])) {
// Get the node ID and load it.
$n = node_load($variables['id']);
$variables['site_category'] = "Breakpoint 1";
//If "Breakpoint 1" shows up on the page output, we know that (isset($variables['id']))
//evaluates as "true"
// Check if the node exists
if ($n) {
$variables['site_category'] = "Breakpoint 2";
//if "Breakpoint 2" shows up on the page output, we know that the ($n) evaluates
//evaluates as true.
I only added the two breakpoints - no other changes were made. When I view the output, only Breakpoint 1 shows up meaning the node doesn't exist.