How to appened a new 'class' attribute to a custom field ? - twig drupal 8 Just started to work around with Drupal 8. 

I want to add class "center-block" to the field_product_image.

&lt;img class="img-responsive {new class}"/&gt;


How do i do this guys?
below is the twig code



   {% if content.field_product_image| render %}
    &lt;div class="col-sm-3"&gt;
    {{ content.field_product_image }}
    &lt;/div&gt;
    {% endif %}
    &lt;div class="col-sm-9"&gt;
        {{ content.body }}
        {{ content.field_features }}
    &lt;/div&gt;
Normally I would say to call addClass() on the image.attributes variable in your image Twig file, but I believe images don't have a lot of template suggestions (everything goes through image.html.twig) which means that your class will be added to all images. Likely not what you're looking for...

Option one, inspect the variables in image.html.twig and see if they give you the information you need to determine when to add the new class. If so, do it in the Twig template (attributes.addClass('new-class')).

Option two, implement hook_preprocess_image in your theme's .theme file. Something like this:

function MYTHEME_preprocess_image(&amp;$variables) {
  if (some_way_to_figure_out_if_this_is_the_right_image) {
    $variables['attributes']['class'][] = 'new-class';
  }
}


Hope that helps. (Edited for better code formatting).