1

I want to add a class in the field label and field items, the HTML I want is the following:

<div class="field field-name-field-price field-type-number-integer field-label-above row">
            <div class="field-label col-md-2">Price:&nbsp;</div>
            <div class="field-items col-md-2"><div class="field-item even">100</div></div>
</div>

I've tried field_formatter_class, the module allow me to add a "row" class into the container, but not in field-label and field-items. I want to add col-md-2 class for such two divs

How to do that without writing a module to do that?

2

have you try hook_preprocess_field().

please check this link everything is given in this blog may be it help you http://atendesigngroup.com/blog/adding-css-classes-fields-drupal

  • Please expand your answer. As it's now it's just a comment. – leymannx Sep 24 '15 at 7:21
1

Are you using views? If so, you can easily add the class by using the Style settings available in Configure field options

enter image description here

Hope this helps!

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.