Quite simply what I would like to do is have a View set up that shows all my content, both published and non-published. But, I want the non-published nodes to show a different background in the table. Is there an easy way to set up this conditional style within a View? Thanks for any help.

Comments

Stefan Lehmann’s picture

Yep .. it's actually quite easy by using tokens, given the token module is installed.

  • Add the "Content: Published" field (if it's not part of your table already) and set it to "Exclude from display" and "0/1" on Output format.
  • Click on "Settings" next to Format: Table.
  • Enter "status-[status]" in the "Row Class" field.

Save the view. Now you should have a class .status-0 for unpublished and .status-1 for published content on the TR tag which you can use to set a specific color.

:-)

I like cookies!

fatalisman’s picture

How to use this with Boolean field?

MikeHauden’s picture

Just ran across this 4 year-old reply and it just saved my bacon. Thanks!

NicholasS’s picture

In drupal 8+ this you use twig now instead of tokens like 

status-{{ moderation_state|clean_class }}
fatalisman’s picture

You can use Views Table Highlighter module.
here