By Eider on
I have created a View with teaser images, but I want the images to have an additional css class for a 3d Carousel.
The current output of the image field:
<div class="views-row views-row-2 views-row-even">
<div class="views-field-field-teaser-fid">
<span class="field-content"><img class="imagefield imagefield-field_teaser" width="205" height="300" alt="" src="http://yoursite.com/dev/sites/default/files/my-image.jpg?1280411025" /></span>
</div>
</div>
I want to add "carousel" to
<img class="imagefield imagefield-field_teaser" .....
How can I achieve this?
Comments
Well, I've solved it so if
Well, I've solved it so if anyone would like to do the same thing:
The name of the view is "collection" and I've created "views-view-fields--collection.tpl.php" with the following content:
I found it not really nice to use str_replace, but I don't know any method that is somewhat better.
Additionally, you can do this
Additionally, you can do this by looking at the Views Theme Information, you can see suggested templates.
Really?
Is it also possible to change the output of the
tag with the templates?
I couldn't find a neat solution to change this output, but had to do a replace with php in order to get add the right css class.
The above code generates
The above code generates errors in Drupal 7. The images do not appear at all. Any ideas as to what modifications need to be done to this php code in order to make it work inside Drupal 7?
Thanks.
you could do this with js
you could do this with js like
$( ".YOURVIEW img" ).addClass( "newClass" )but this is of course only workin if js is enabled
i used it once to get a reflection workin..this reflection works only if js is enabled anyway so i didnt needed the class if js was disabled
its not the best solution..but the easiest i think
Method I used
I ended up using THEME_preprocess_image() in template.php
Here is a code snippet:
Hi gone404
Hi gone404
I'm trying to preprocess my image style like this example
<img class="media-object img-rounded img-responsive" src="http://placehold.it/350x250" >My preprocess_image function is not adding any classes?
Many thanks for your help
You may want to try this!
You may want to use this into your CSS code:
The trick is it selects and style every "img" tag element where the parent is a "field-content" class element.
Example:
Select and style every "p" tag element where the parent is a "div" tag element:
You can add the following css
You can add the following css to select img tag easily