I have a page node template named page--node--content_type_name.tpl.php
when I try calling fields using eg print render($content['field_article_author']); nothing appears , how else can I call this fields ?

Comments

preksha’s picture

For this, hide that field from content like this:

  hide($content['field_article_author']);
  print render($content);

And use the render() function and the field name to print the field somewhere else:

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

If it is still not showing anything, try to debug $content array. if you have Devel module enabled you can simply place dsm($node); in the template to print out the node object.

Also check, Is the field enabled on the manage display tab for the content type?

Thanks,
Preksha

er.pushpinderrana’s picture

Alternative is $node variable that you can use instead of $content but in special scenario. In your case first check your Manage Display setting of this content type to make sure this field is not hide from there.

Pushpinder Rana #pushpinderdrupal
Acquia Certified Drupal Expert

adrianqx’s picture

Hello

<?php
 print render($content['field_article_author']); 
?>

just dosen't work it works well in node--contenttype_name.tpl.php but will not display in page--node--contenttype_name.tpl.php which I prefer using since I can alter the whole template layout as i please

er.pushpinderrana’s picture

Use correct variable if you are using page template. See Here

you can use here $node object.

Pushpinder Rana #pushpinderdrupal
Acquia Certified Drupal Expert

adrianqx’s picture

finally figured it out

use

<?php
 print render(field_view_field('node', $node, 'field_your_field', array('label'=>'hidden'))); 
?>
er.pushpinderrana’s picture

Great!

Please edit your original thread and append [SOLVED] either in start or end of title. It would help other readers to understand the status of this post.

Thanks!

Pushpinder Rana #pushpinderdrupal
Acquia Certified Drupal Expert

Cwiggo’s picture

Brilliant. Worked for me too.

vmevada102’s picture

This code worked successfully using this above said code.

Kindly help me to hide the empty field for above said code.

jmcerda’s picture

You should put that in a variable first -

    $my_value = field_view_field('node', $node, 'my_field', array('label'=>'hidden'));
    print render($my_value);
Jabastin Arul’s picture

@adrianqx: Wowwww!!!Its really worked fine for me..

seenafallah’s picture

It dosen't work in Drupal 7.55
It gets me this error:

Notice: Undefined variable: node in include()
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids()

Any other solutions?

Tonton2’s picture

The last solution kind of worked for me. I am using Drupal 7.59
The image shows up but I get an error message: Strict warning : Only variables should be passed by reference

Tonton2’s picture

I watched how I did on another site earlier.

<?php if (!empty($node)):
	$fieldImage = field_view_field('node', $node, 'field_image', array('label'=>'hidden'));
	if ($fieldImage): ?>
		<?php print render($fieldImage);
	endif;
endif; ?>