I added a new field "mood" (image) to the page content type. Is there any way to access the image stored in this field in the page.tpl.php?
Asked
Active
Viewed 2.2k times
2 Answers
10
Should be
$node = node_load($nid);
$node->field_mood[$node->language][0]['value'];

JochenJung
- 7,183
- 12
- 64
- 113
8
There is a new "field_get_items()" function in drupal 7. The $node variable should already be defined in page.tpl so the first line may not be required.
This will get the field in the appropriate language. There is also an optional parameter to specify the desired language if needed.
$node = node_load($nid);
$values = field_get_items('node', $node, 'mood');
if ($values != FALSE) {
$val = $values[0]['value'];
}
else {
// no result
}
reference: http://api.drupal.org/api/drupal/modules--field--field.module/function/field_get_items/7

idFlood
- 1,016
- 10
- 20
$node = menu_get_object();
since it gets the node from the page cache. – Capi Etheriel Jan 18 '12 at 15:41