I want to print things like:

$field_image
$field_body
$field_description

in my tmeplate.

Which are normally all printed inside:

$content

What syntax do I need?

Thanks

Comments

mistresskim’s picture

If you want to print out variables in a node/content type, you can use the $node object, which has all your variables inside of it.

Use print_r($node) or dsm($node) (if you have the Devel module installed) from within your template file so you can see how to dial up your fields, then output them using print statements.

For example, if you have a textfield 'field_name', its structure inside the $node object might look something like this:

[field_name] => Array
(
[0] => Array
(
[value] => John

So you could print it using:

print $node->field_name[0]['value'];
unxposed’s picture

Thank you very very very much : ) I really needed that pointer.

Here's how I can now display the content on my Organic groups home pages:

<?php print $node->field_image[0]['view'];  ?>   
<?php print $node->field_description[0]['value'];  ?>
<?php print $node->field_more[0]['value'];  ?>

<?php print $node->content['view']['#value']; ?> 

Thanks again!

molave’s picture

This was, indeed, a quick and clear solution to a specific question. =)

Just a follow up. If the field holds multiple values, the following code displays only one value, the first, because of '[0]'.

<?php
print $node->field_name[0]['value'];
?>

Is it possible to edit this to display all the values?

wolf_22’s picture

Hey, molave... I caught your thread here while searching for a way to display only specific pieces of data while avoiding the possibility of breaking the "Edit Page" capability... (You might check this as I've taken the approach outlines in this thread and found that I can no longer edit the page! Ha. I think it will be an easy fix, but if you're aware of what I'm referring to here, by all means, feel free to explain the solution.)

Anyway, you can output all values:

<?php
foreach($node->field_name as $k=>$v){
   print $node->field_name[$k]['value'];
}
?>

(Unless I'm mistaken, that is. ;.) )

Hope this helps and again, if you're in the privy of a solution to the problem I've mentioned above, please let me know. Us Drupal guys need to know when to reach out to our sleeper cells, ya know? ;.)

jaron’s picture

How do you do that with an output from views? I have a scenario where I'm using a list created from Nodequeue. It outputs both the title of a series of nodes and images in each node. But I want to put the titles in the left sidebar and the images in the center content area. Any advice?

Thanks!

molave’s picture

@Wolf_22

Thanks for the help with the syntax. It does the trick, all right. This notification slipped under my radar, because dude I'd never skip showing appreciation for a helping hand.

Cheers!