This doesn't strike me as a very complex problem so I'm hopefully just missing something obvious.

I've got a views_bootstrap grid that shows fields of multiple content types. However the View doesn't output what content type each element is.

How can I get the content type in the markup as a css class which I then can style?

Use case: I'd like to be able to style grid elements different on basis of what content type it is. For example:

  • Grid elements of content type 1 should be 400px high
  • Grid elements of content type 2 should be 650px high
  • Can be done as a view mode too, and adding the content type as a variable in a preprocess, then just render that mode with Views.
    – Kevin
    Nov 15, 2017 at 14:29

1 Answer 1


You could add in your view a hidden field with the content type and either rewrite the results of each field and add wrapper to each field using the available value (content type) or theme the specific view and add a class to the row wrapper based on content type (which still is passed to your view as a field).


In case you need to add a class to the row:

For D7 in Advanced settings you can check the theme: information and create template file for your rows based on the suggestions of the informations.

If you work on D8 you can create a template file check (https://api.drupal.org/api/drupal/core%21modules%21views%21templates%21views-view-grid.html.twig/8.0.x) where you have all the views data so as you can add all a wrapper to each row.

Whatever version you use have a look at theme hook suggestions D7 - https://www.drupal.org/docs/7/theming/template-theme-hook-suggestions and D8 - https://api.drupal.org/api/drupal/core%21modules%21views%21views.theme.inc/group/views_templates/8.2.x in order to make sure how to name your template and which template you really need.

If you just need to add a class to a field:

In your views put your content type field at the top of the fields and add a new field or edit an existing one. Go to REWRITE RESULTS and select Rewrite the output of this field. Below of this you will find a list of all the replacement patterns which you can use to create your own markup with all the details you need.

Good luck!

  • I actually have a field showing the content type (here's the dev site: drupal-85630-345685.cloudwaysapps.com). I don't know how to go from there to an enclosing div around the entire grid element though... Nov 15, 2017 at 16:43
  • Are you on D7 or D8? I'll update my answer.
    – Ismini
    Nov 15, 2017 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.