Change style of custom view mode condionally I have a custom view mode created with ds module,
this view mode lists node articles, each article displays like this :


  
  title
  description
  url
  term reference field
  some other fields...
  


I want to add some style condionally depending on the term reference field
For example: 
the first article has the term reference with the value "1", I change the backgroud of the this article to "red"
the second article has the term reference with value "2", I change the backgroud to "green"
...

EDIT :

this is an image how look like the manage display of some fields :


My interest is with the Flag field:
It's a taxonomy field reference having (title, color (hexadecimal value), description...)
This flag field as you see has the formatter 'editable' (done with editablefieds module), so editors can edit the value of this field.

Now I want to add another field next to Flag witch is the color field of the current Flag taxonomy term, and render for example a simple div with some width and height and with the backgroun-color, this color field

Hope it's more clear than the old post :)

Thanks in advance.
This is pretty similar to How to provide template for particular view mode? where as you can add custom php code to add further variables used in that viewmode or add simple if/ else/ in_array to the used template (this is not limited to a custom template - you can always override the default node.tpl.php in your theme.

UPDATE: add only a css class depending on the term reference field.

// can also be THEME_
function MYMODULE_preprocess_node(&amp;$vars) {
  if ($vars['view_mode'] == 'myviewmode') {
    if(isset($vars['node']) &amp;&amp; isset($vars['node']-&gt;field_my_term_reference)) {
      // class to add a general has-term-reference-class
      $vars['classes'][] = 'has-term-reference';
      // add a specific term-reference-class
      foreach($vars['node']-&gt;field_my_term_reference as $tid) {
        // class based on term id
        $vars['classes'][] = 'term-id-' . $tid;
        // class based on term name
        $term = taxonomy_term_load($tid);
        $vars['classes'][] = 'term-name-' . $term-&gt;name;
      }
    }
  }
}