I have created views in which i have added custom text and Math expression.
I displayed view in table format
I created one Math expression which is noticed below:

[Field 1] - [Field 2]

I have displayed this expression into another custom field in views.
Now i want to add some condition statements.
That is

If [expression] >= 0
 'display something'
 'other texts'

Is it possible to add conditional statement in Math expression views?

1 Answer 1


Well you can override any of the output you have from views with a template override.

Goto your Views > Display

on the right hand side in the box labelled 'other'

click on information next to 'theme'

This will give you a list of template pages you can use to over write the section you need. A little trial and error maybe needed at first until you get used to what your being presented.

on the left hand side of the page suggested you have a link to the code you need to use. Copy that code and paste it into the file name your targetting ( ie views-view-field--default.tpl.php ) and add in the theme/templates folder your using.

from here on you can manipulate the code how you want using php

Hope this makes sense, as I wrote it real quick :)

  • Ya i know this. But if i follow your answer, then i need to create new tpl file for every views. I don't need to do this. Mar 5, 2015 at 9:20
  • you could target for the custom field instead. and reuse that for each view. would that solve your problem.
    – Deejay
    Mar 5, 2015 at 10:17
  • I have added custom field only. I want to change the content of field based on another field. It is possible in views Mar 5, 2015 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.