By mortenson on
Hello, I want to colour a Views result text.
I have created a 'select list' field type. So I want the text to be coloured when Views displays the results.
For example: red for "Bad", yellow for "more less", green for "good"
I thought of doing it in CSS, but I will need some IF conditions in PHP code, right?
thanks.
Comments
Look at the theme
Look at the theme documentation for views, you can override the theme function for a single field. In this case I would add a class to the surround div that reflects the value of the field and then add css to apply the color based on the classes.
Ok, I can build 3 new clases
Ok, I can build 3 new clases in style.css, one for red text, another for green text, another for yellow text.
now, If I edit my views, and then go to theme:Information, I can see the field I want get colored.
If I double click on:
Field Contenido: Text: opinion (field_select) (ID: field_select_value): views-view-field.tpl.php
I just get:
print $output;Should I edit this code? how?
still stuck here
still stuck here
ok finally did it! Here is
ok finally did it!
Here is how:
Create 3 new clases in your file style.css
Now create this file in the theme folder (the one you are using):views-view-field--viewname--fieldname-value.tpl.php
In my case I named the file: views-view-field--ppppppp--field-select-value.tpl.php
Now put the code you need in that file.
I used:
print $output;the $output variable contains what it is being outputed in your field.
good luck!
realy nice !!
just wonderd how did you passed the div/ class value so that the right css will be activated ?
Thanks,
Rami