0

On a page that displays pictures that have two different classes, how to I apply an image style to one class and not to the other?

Or, how do I apply different image styles to images that have different classes?

Thanks. :)

1

Image styles and HTML classes on images are completely unrelated, so you would have to do some sort of manual hack to achieve this. A very basic effort might be to use hook_preprocess_image_style like so:

function MYTHEME_preprocess_image_style(&$vars) {
  if (array_search('some-class', $vars['attributes']['class']) !== FALSE) {
    $vars['style_name'] = 'some_style';
  }
  elseif ($another_condition) {
    $vars['style_name'] = 'some_other_style';
  }
}

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.