Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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.phpAccess 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?

Devl Output

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.

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?

Devl Output

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.

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?

Devl Output

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.

deleted 295 characters in body
Source Link
Allan
  • 563
  • 5
  • 19

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?

Devl Output

I have added the following code with a reference to the field that is displaying in Devel:

<?php
function bricks_preprocess_page(&$variables) {

  if (isset($variables['id'])) {
    // Get the node ID and load it.
    $n = node_load($variables['id']);
     
$variables['site_category'] = 'Breakpoint"Breakpoint 1';
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";
 // Just 
 using the//if body"Breakpoint field2" asshows anup example.
on the page output, we know $variables['site_category']that =the ($n->field_site_category['und'][0]['target_id'];
) evaluates  
  }
//evaluates as }
}
?>true.

I only added a "breakpoint" that sets the two breakpoints site_category field to some text- no other changes were made. When I try this setup,view the breakpoint textoutput, only Breakpoint 1 shows up. If I create another breakpoint by making this modifcation:

//$variables['site_category'] = $n->field_site_category['und'][0]['target_id'];
$variables['site_category'] = 'Breakpoint 2';

The variable site_category stays at "Breakpoint 1" meaning the "check if the node exists" comes back false. This I don't understand...doesn't exist.

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?

Devl Output

I have added the following code with a reference to the field that is displaying in Devel:

<?php
function bricks_preprocess_page(&$variables) {

  if (isset($variables['id'])) {
    // Get the node ID and load it.
    $n = node_load($variables['id']);
    $variables['site_category'] = 'Breakpoint 1';


    // Check if the node exists
    if ($n) {
      // Just using the body field as an example.
      $variables['site_category'] = $n->field_site_category['und'][0]['target_id'];
    }
  }
}
?>

I added a "breakpoint" that sets the site_category field to some text. When I try this setup, the breakpoint text shows up. If I create another breakpoint by making this modifcation:

//$variables['site_category'] = $n->field_site_category['und'][0]['target_id'];
$variables['site_category'] = 'Breakpoint 2';

The variable site_category stays at "Breakpoint 1" meaning the "check if the node exists" comes back false. This I don't understand....

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?

Devl Output

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.

added 1065 characters in body
Source Link
Allan
  • 563
  • 5
  • 19

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?

Devl Output

I have added the following code with a reference to the field that is displaying in Devel:

<?php
function bricks_preprocess_page(&$variables) {

  if (isset($variables['id'])) {
    // Get the node ID and load it.
    $n = node_load($variables['id']);
    $variables['site_category'] = 'Breakpoint 1';


    // Check if the node exists
    if ($n) {
      // Just using the body field as an example.
      $variables['site_category'] = $n->field_site_category['und'][0]['target_id'];
    }
  }
}
?>

I added a "breakpoint" that sets the site_category field to some text. When I try this setup, the breakpoint text shows up. If I create another breakpoint by making this modifcation:

//$variables['site_category'] = $n->field_site_category['und'][0]['target_id'];
$variables['site_category'] = 'Breakpoint 2';

The variable site_category stays at "Breakpoint 1" meaning the "check if the node exists" comes back false. This I don't understand....

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?

Devl Output

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?

Devl Output

I have added the following code with a reference to the field that is displaying in Devel:

<?php
function bricks_preprocess_page(&$variables) {

  if (isset($variables['id'])) {
    // Get the node ID and load it.
    $n = node_load($variables['id']);
    $variables['site_category'] = 'Breakpoint 1';


    // Check if the node exists
    if ($n) {
      // Just using the body field as an example.
      $variables['site_category'] = $n->field_site_category['und'][0]['target_id'];
    }
  }
}
?>

I added a "breakpoint" that sets the site_category field to some text. When I try this setup, the breakpoint text shows up. If I create another breakpoint by making this modifcation:

//$variables['site_category'] = $n->field_site_category['und'][0]['target_id'];
$variables['site_category'] = 'Breakpoint 2';

The variable site_category stays at "Breakpoint 1" meaning the "check if the node exists" comes back false. This I don't understand....

More expanded output of Devel
Source Link
Allan
  • 563
  • 5
  • 19
Loading
added 229 characters in body
Source Link
Allan
  • 563
  • 5
  • 19
Loading
edited tags
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Loading
Source Link
Allan
  • 563
  • 5
  • 19
Loading