0

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 looks like so:

function bootstrap_subtheme_preprocess_image(&$variables) {
  if(isset($variables['style_name'])) {
    if($variables['style_name'] == 'logged-in') {
      $variables['attributes']['class'][] = "media-object";
      $variables['attributes']['class'][] = "img-responsive";
      $variables['attributes']['class'][] = "img-rounded";
    }
  }
}

But it is not adding the classes.

Why not?

  • Note that only images that are theme'd with a theme('image') call will work in this way. Regular <img> tags won't. – AyeshK May 16 '14 at 18:13
-1

Try this.

function mytheme_preprocess_image(&$variables) {
   if(isset($variables['style_name'])) {
    if($variables['style_name'] == 'image_style') // this is an image style used in drupal's image styles {
     $variables['class']['img-responsive'][] = "true";
  }
 }
}

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.