I would like to know how I can rewrite the display of a field in a content type, based on another field.

For example, when I have a "date" field for an event, and a "display_date" to override it when the date is not known, I would like to make a view that grabs the upcoming events and displays them like this:

  • tue 17/07: Event W with known date
  • end of July: Event X (for which the date will be announced soon)
  • sat 04/08: Event Y with known date
  • early 2013: Event Z (for which the date will be announced much much later)

Selection and sorting was easy, but I'm struggling with the display part. In PHP it's simple:
$row_text = (($display_date==null)?$date:$display_date).": ".$event_title_with_link;
But how should I do this in Drupal? I have the latest 7.14 with Date module installed, if it matters.

Comments

johnv’s picture

If you want to show the node, I don't know how to do this,
but if you want to show a Views with fields, you do as follows:
- enable Views + Token + Entity token(?)

- create a view with fields display_date and date in this order(!).
- exclude display_date from view.
- for date, set 'NO RESULTS BEHAVIOR' and and use a token:
[field_display_date]: [title]
(you can only use tokens from fields earlier in the field-list.)

method: use REWRITE RESULTS for the date field.