lwinkyawmyat
lwinkyawmyat

Reputation: 1242

drupal - How to add custom CSS in View Module For each Grid Format?

I have a grid image gallery built with view module. And I want some effect for each image.

So,I try to add custom css class to each img tags.But I cannot it. Please tell me "How to add custom css class in view module and grid format"?

Upvotes: 0

Views: 621

Answers (2)

rana_gee
rana_gee

Reputation: 43

Hi this is simple no need to do this in coding, just do following.
1- Add a new field (Global Result counter) in your view and exclude it from display.
2- Exclude your image field from display.
3- Add a new field Global Custom text field, here you can add token of field Result counter to your image field, like following.

<div class="Image-[put-result-counter-token-here]" > [token-for-image-field]</div>

This will output a dynamic class for your image field.

Upvotes: 1

Vishal Patil
Vishal Patil

Reputation: 485

You need to preprocess image style as follow:

/**
 * THEME_preprocess_image_style() is also available.
 */
function <THEME_NAME>_preprocess_image(&$variables) {
    if (isset($variables['style_name'])) {
        if ($variables['style_name'] == 'thumbnail') {
            $variables['attributes']['class'][] = "<YOUR CLASS NAME>";
        }
    }
}

Add above code in your template.php file of the current theme & clear cache.

Remember to replace text placed under <> in above code with appropriate values.

Upvotes: 1

Related Questions