Community

Views: triple rewriting of field output

I'm displaying list of nodes via views. I want to display one fields (from 3 available). Let's say I have values: v1, v2 and v3. If v1 is present - display it. If not - display v2. If v2 is not present too - then display v3.
Trying to work with excluding dispay for some fields, and rewrite outputs of other:

v3:
Exclude from display: yes
Hide if empty: yes
Do not rewrite if empty: yes

v2:
Exclude from display: yes
Rewrite the output of this field: [v3]
Hide if empty: yes
Do not rewrite if empty: yes

v1:
Exclude from display: yes
Rewrite the output of this field: [v2]
Hide if empty: yes
Do not rewrite if empty: yes

Is it even possible to do with Views interface or I just need to manipulate field templates. If so - how can I achieve my goal?

Comments

=-=

to the best of my knowledge you can't do this through the UI. it seems you want some if else statements in a custom tpl.php or use php through the UI.

I tried it too. What exactly

I tried it too.

What exactly I want to do, is to display thumbnail image on list of about 100 elements. In some case (if image is not present) instead of image thumbnail, I want to display video thumbnail (module Embeded Media Field / Drupal 6).

So I have this code:

content_view_field(content_fields("field_video"), $node, true, FALSE)

That generates field view for node teaser, where I can setup wich view of field (video, thumbnail, text etc.) I want to use. My code need to load $node object. But if I have list of 100 nodes, it can't work like that - it takes too much calls to db and it's not efficient.
I don't know how to access to $node in template, or there is another way for sure. Probably it's somewhere in $view variable.

Try a CSS solution

I haven't tried this with 3 fields but I have used it with two dependent fields and the principal will work, it will just require more leg work.

It requires the field to be displayed twice, once for the actual displayed output of the field and their other to be rewritten to be the addition class or id which is display:none; in your css. This class or id needs to then be part of the rewrite of the dependent field:

Fields:

- FieldA-1
Rewrite: <div class="[fieldB-2]">[fieldA-1]</div>
- FieldA-2 Exclude from display
Rewrite: hiddenClassA

- FieldB-1
Rewrite: <div class="[fieldA-2]">[fieldB-1]</div>
- FieldB-2 Exclude from display
Rewrite: hiddenClassB

CSS:
.hiddenClassB,
.hiddenClassA {
display:none;
}