0

Is there a way to add a specific class to the img tag in a view? I'd prefer to use a template to perform it. I can see how I can change what classes the image is wrapped in, but I don't see a way to edit the classes of the img tag itself.

I see there's a way to edit the image field using views-view-field--field-image.tpl.php however the only variable I can see that is available is $output.

3

If .myclass img { your code goes here } is not good enough and you must have the class inside the img tag, then:

1) Download and enable the Image URL Formater Module

2) On your view's picture field, select url as format.

3)

Option A) In the rewrite results field type <img src="[field_image]" class="yay-we-did-it">

Option B) if you want to use the .tpl.php file, put this inside it.

<img src='<?php print $fields["field_image"]->content; ?>' class='yay-we-did-it'>

  • I edited my answer to provide a tpl answer. – No Sssweat Jun 4 '15 at 12:58

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.