0

I tried to build a soccer magazine website. I want to display Match Win/Loss/Draw in the Match Result Page with the score result. I want to display it like:

if [field_score1] > [field_score2] display 'Win' if [field_score1] < [field_score2] display 'Loss' if [field_score1] = [field_score2] display 'Draw'

Im stuck please Help.

1 Answer 1

0

First, In your Match Results view, add a Global: Custom text field and just leave it blank/empty. (we will use this field to print the outcome)

You can override the view's display through your themes template file.

Go to sites/all/themes/YOURTHEME/ look for template.php and open it. You probably have other code inside there, so make extra space by hitting enter at the bottom and add the following code.

function YOURTHEME_preprocess_views_view_fields($vars){ if ($vars['view']->name == "VIEWNAME" && $vars['view']->current_display == "DISPLAY" && $vars['fields']['field_score1']->raw > $vars['fields']['field_score2']->raw){ $vars['fields']['nothing']->content = print 'Win'; } else if ($vars['view']->name == "VIEWNAME" && $vars['view']->current_display == "DISPLAY" && $vars['fields']['field_score1']->raw < $vars['fields']['field_score2']->raw){ $vars['fields']['nothing']->content = print 'Loss'; } else if ($vars['view']->name == "VIEWNAME" && $vars['view']->current_display == "DISPLAY" && $vars['fields']['field_score1']->raw == $vars['fields']['field_score2']->raw){ $vars['fields']['nothing']->content = print 'Draw'; } } 

Replace YOURTHEME with your actual theme name

Replace VIEWNAME with your view machine name. (example: match_results)

Replace DISPLAY with your display machine name. (example: block, block_1 ) You can find the name by looking at your view. (see picture below). If you're using the Master view, then the machine name is "default"

enter image description here.jpg

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.