0

My field_image is not rendering on user-profile.tpl. I have the following code (two different ways to render for testing):

    $image = field_get_items('user', $user, 'field_image');
    $output = field_view_value('user', $user, 'field_image', $image[0], array(
      'type' => 'image',
      'settings' => array(
        'image_style' => 'header_image_160x160',
      ),
    ));
    print render($output);

This produces the following in html:

<img src="https://coinme.io/sites/default/files/styles/header_image_160x160/public?itok=f31sbmSd" width="160" height="160" alt="">

I get the dead image logo. It is missing the final part of the file structure. And this is how I normally render:

$to_render = field_view_field('user', $user, 'field_image', array('settings' => array('image_style' => 'header_image_160x160'))); print render($to_render);

This is showing the default image, even though the image does exist:

https://coinme.io/sites/default/files/styles/header_image_160x160/public/images/profile/profile-large.png?itok=rb-2qFOw

I have the same field in a content type which is rendering correctly (only difference being the $user user -> $node node.

<?php $to_render = field_view_field('node', $node, 'field_image', array('settings' => array('image_style' => 'header_image_160x160'))); print render($to_render);?>

So it appears that when using user-profile specifically is the issue. I have also tried adding a new field type and same effect. Any suggestions?

Thanks, Paul.

  • Are you sure $user is in scope and that the field name is field_image? It looks like one of those things is causing the actual filename to be unavailable. – David Thomas Jan 12 '14 at 11:07
  • 1
    @DavidThomas I just came to the same conclusion. It didn't occur to me until I did a print_r($user) and got my logged in user. Thank you for getting involved. – Paul Jan 12 '14 at 11:30
0

The answer was simple, $user is the user logged in. As my logged in user didn't have a profile image, all I kept seeing was the default. Unfortunately, elsewhere on the page I am not using $user but just $field_*, so it looked like I was using the right variable. This fixed it:

<?php $account = $elements['#account'];?>

And then updated $user to $account.

<?php $to_render = field_view_field('user', $account, 'field_image', array('settings' => array('image_style' => 'header_image_160x160'))); print render($to_render);?>  

You cannot believe how much time and searching I did to fix this, and it turned out I was looking at the wrong variable the whole time.

Thank you, Paul.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.