1
votes

I'm developing a drupal website and I'm using views module to create a block. I'm displaying a view as fields. In my custom module I want to add class name to one view's field if one other field's value is 0.

How to do this?

EDIT*

I found solution to my problem. See my answer below. I didn't mark it as accepted because it actually don't answer my original question how to add the class name programmatically. I'm still interested to know how to do it programmatically so if someone has good answer for me I will mark it as accepted.

1

1 Answers

0
votes

I found solution to my problem. The solution doesn't require coding or custom module and can be done only with views settings.

First I excluded the field from the display where I wanted the class name be. Then the other field I overwrote like this: <div id="field1">[field1]</div><div id="field2">[field2]</div>.

I also overwrote the field2 when its empty and checked the settings that 0 will be also counted as empty. In the overwrite I added the class name: <div id="field1" class="something">[field1]</div><div id="field2">[field2]</div>

Now when the field2 is 0 it will be overwritten and it will display the field1 with class name.