Drupal – Replace node link text with image on view
Drupal Views are great for their flexibility and ease of use. It’s often useful to output a teaser with a ‘read more’ link back to the node. Somtimes we need to link to a node from an image instead of text. Drupal doesn’t provide an option for an image link but it’s pretty simple to override the template file. The code below will replace the link text with an image.
Create a new php file in your themes folder with the name of the field view you want to override. In most cases, the name will contain view-node. You can see the theming information by going into the view, and clicking Theme: Information under Basic Settings.
ie. views-view-field–front-blocks–view-node.tpl.php
//output image link instead of text $field_text = $field->options['text']; $image_file = '/images/but_' . strtolower($field_text) . '.gif'; $field_image = '<img src="/' . path_to_theme() . $image_file . '" alt="' . $field_text . '" border="0" />'; $new_output = str_replace($field_text, $field_image, $output); print $new_output;

August 7th, 2009 at 6:38 am
Many thanks, gotta love Google. Saved me many hours working this out.
August 21st, 2010 at 4:48 pm
Thank you so much for posting this code. It helped me out a lot. I don’t have the $field_text in my image name, so this version of the above code worked for me:
$field_text = $field->options['text'];
$image_file = ‘/images/readmore-button.gif’;
$field_image = ”;
$new_output = str_replace($field_text, $field_image, $output);
print $new_output;