D
D
Dima4jin2014-09-22 10:19:05
Drupal
Dima4jin, 2014-09-22 10:19:05

How to correctly display a field in Drupal 7?

Based on these two articles , Wikidrupal
Habr is trying to display the user's avatar field on the material page, in the node.tpl.php file. I tried it in different ways, for example:

<?php
    global $user;
    $user_data = user_load($user->uid);
    $field = field_get_items('user', $user_data, 'field_userphoto');
    $output = field_view_value('user', $user_data, 'field_userphoto', $field[0]);
    print render($output);
  ?>

Result: Fatal error: Cannot access empty property in /var/www/globa2_js/data/www/globa2.jaguarsoft.ru/modules/field/field.attach.inc on line 324
What's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2014-09-22
@Dima4jin

print drupal_render(field_view_field('user',$user_data,'field_userphoto',array()));

If you need a field without a header ( label ) - the last parameter is passed not an empty array, but array('label' => 'hidden');

D
Drupby, 2014-09-22
@drupby

https://www.drupal.org/node/2051839

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question