0

I have a View that displays a list of all the content types, with price as one of the fields you can sort and filter by.

However, the client wants to have some items show up without a price, i.e something like "Price on demand" / negotiate.

Therefore I want to replace '0' value to show up as that text (translated for other languages), how would I best do this?

I use some exposed range filter in my view but couldn't see any extra functions to replace values of field items with strings etc.

I would need it changed in the View as well as the items' individual page (and generated PDF file, but that part I can do)

EDIT: I have Better Exposed Filters, but after setting the replacement as:

0|Price on demand

It didn't seem to work or do anything. However my views uses a template, and I output the price by doing:

print render($content['field_price']);

So I would first need to check if $content['field_price'] value is 0, then output my text string? Ideally I would prefer using some settings that can handle replacing the value for me.

1 Answer 1

2

This seems like the simplest method:

print $content['field_price'][LANGUAGE_NONE][0]['value'] == 0 ? 'Price on demand' : render($content['field_price']);
3
  • $content['field_price'] is Array
    – dan2k3k4
    Commented Mar 28, 2014 at 16:02
  • So it is. Not 100% sure of the structure of your field_price but something like my updated answer should do the trick...
    – Felix Eve
    Commented Mar 28, 2014 at 16:05
  • Got it working with: $node->field_price['und'][0]['value'] == 0 ? t('Price on demand') : render($content['field_price']); Thanks
    – dan2k3k4
    Commented Mar 28, 2014 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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