How to print fields manually I am using print module. I am also using devel module. In print.tpl.php file, I see a php code that prints the content as print $content. I don't want to print the entire content. I think content is an array. How can I print manually some fields from the content variable using the devel module or in php?

Thanks.
D




1. 



  print render($content['field_machine_name']);


Get this error:
 Fatal error: Only variables can be passed by reference in /..sites/all/modules/print/print.tpl.php on line 100                     



  php  print $content['field_machine_name'];



I get left error only (&lt;)


3. 



  print $fields['field_vehicle_options']->content;


I get completely blank



I am using bartik 7.22.


themes > bartik > template.php


Added the below function.

function bartik_preprocess_print(&amp;$vars, $hook) {

// Global node.
$node = $vars['node'];

// Create a var and render using field_view_value
$vars['test'] = field_view_value('node', $node, 'field_price', $node-&gt;field_price[$node-&gt;language][0]);

}



themes > bartik > template > print.tpl.php


I added:
print render($test);


I went to my page
http://bettylist.com/ac/node/12 > clicked printer friendly link >
I did not see the value of variable.


In print.tpl.php, what works:

print $content; //I GET CONTENT IN PRINT PAGE
print dsm($title); // I GET VALUE OF TITLE IN PRINT PAGE


Please advise.
Thanks,
D



It worked. I have added one more variable as below:

function bartik_preprocess_print(&amp;$vars, $hook) {

// Global node.
$node = $vars['node'];

// Create a var and render using field_view_value
$vars['price'] = field_view_value('node', $node, 'field_price', $node-&gt;field_price[$node-&gt;language][0]);


// Create a var and render using field_view_value
$vars['vehicleOption1'] = field_view_value('node', $node, 'field_vehicle_option_1', $node-&gt;field_vehicle_option_1[$node-&gt;language][0]);

}


In print.tpl.php, I added

print render($test);
print render($vehicleOption1);


But I am only getting the value of the last variable $vars'vehicleOption1'.

Please advise.
Try with this:

&lt;?php print render($content['your_field_name']); ?&gt;


This should print the field you want.

Change 'your_field_name' with machine name of the desired field.

You can install and enable Devel module and add this:

&lt;?php dsm($node); ?&gt;
&lt;?php dsm($content); ?&gt;


in your print.tpl.php file. You will see all $node and content fields.

UPDATE

Also, you can add this function in your template.php file:

/**
  * Renders the content of the print page using the theme api.
  */
function THEME_preprocess_print(&amp;$vars, $hook) {

// Global node.
$node = $vars['node'];

// Create a var and render using field_view_value
$vars['any_variable'] = field_view_value('node', $node, 'your_field_name', $node-&gt;your_field_name[$node-&gt;language][0]);

}


Replace THEME with your theme name, any_variable with any name you want for this variable and your_field_name with machine name of your field.

After this you can render your field in print.tpl.php file like this:

&lt;?php print render($any_variable); ?&gt;


Again, change any_variable with the name you choose for this variable in function from template.php file.