I am trying to print each row with custom HTML. I need to display the image field wrapped inside the image link. I have this in the tow style output template:

<div class="myRow">
    <div class="myImg">
        <a href="<?php print $fields['field_news_link']->content; ?>" target="_blank"><img src="<?php print $fields['field_news_image']->content; ?>" /></a>
    <a href="<?php print $fields['field_news_link']->content; ?>"><?php print $fields['field_news_source']->content; ?> /></a>

The link part is working, but the image does not display. In the HTML I get:

<img src="<img src=" http:="" localhost:8888="" test="" sites="" default="" files="" styles="" featured_image="" public="" 10.27.14%20cnbc.png?itok="MGeDqtuK&quot;" width="200" height="150" alt="my alt tag">

On the front end, I see the broken image square and '/> directly after. What am I doing wrong?

1 Answer 1


You need to print image src like this:

<?php print file_create_url($uri); ?>

Just change $uri with uri of your image ($fields['field_news_image']...)

Take a look on function file_create_url as well.

  • I just get the based url return when I do <img src="<?php print file_create_url($fields['field_news_image']); ?>" />. And I still have stray /> characters, which tells me that is syntax issue.
    – srodrig
    Commented Jul 15, 2015 at 18:08
  • you need to go deeper, not just $fields['field_news_image'], use Drush to find the "path" to uri of your image...
    – mixerowsky
    Commented Jul 15, 2015 at 18:16
  • How do I use drush to find path to uri? Also, my view is set to show Fields instead of Content. And the Image field formatter is set to Image instead of File rendered. Does any of this affect my approach? And the code I am using should be entered into the Row output template or Style output template?
    – srodrig
    Commented Jul 15, 2015 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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