0

I am using the file_create_url() function to create the URL for images. The code is:

<img src="<?php echo file_create_url($node->field_history_image['und'][0]['uri']); ?>">

But I just noticed that the alt and title attributes are not added to the HTML output, eventhough I added them for the image in the admin.

How would I change the above code, so that it adds the alt and title attributes if they are filled in the Admin interface. Or what other function should I use?

Thanks.

Boutros.

1

Since you are rendering a field , you can use below code

<?php
$image = field_get_items('node', $node, 'field_history_image');
$output = field_view_value('node', $node, 'field_history_image', $image[0]);
print render($output);
?>

OR

$view = field_view_field('node', $node, 'field_history_image');
print render($view);
1

Here is my answer to my own question:

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

The above code, prints the image (the URL and the alt and title attributes if they exist). It does exactly what I wanted.

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.