Views - Rewrite output

The results from your view can be altered or rewritten to add additional functionality to your website.

In a view, when you add a field, you can manipulate that field.

Add a new field to your view through the standard process.

When you add a new field, scroll down to the rewrite results sub group and click it to use the rewrite functionality.

Clicking the no results behavior will show the functionality.

The default options for rewriting is:

  • Rewrite the output of this field
  • Output this field as a link
  • Trim this field to a maximum length
  • Strip HTML Tags
  • Remove whitespace
  • Covert new lines to HTML BR tags

The first and most popular option is the, Rewrite the output of this field.  Checking this box exposes a lot of great functionality.

Through the text box, you can add replacement patterns.  Replacement patterns, or tokens, can be used to display the results.  The available replacement patterns can be influenced by the modules you have installed, which can provide additional replacement patterns.  The primary source of replacement patterns is the other fields you have selected for your view.  If you have selected title, body, date, those fields will be available for use as replacement patterns.  Some fields, have additional information in the background that will be available as a replacement pattern.

In this example, title and body fields were selected for the view.  You can see the additional replacement patterns available like body-summary and body-format.

With your available replacement patterns, you can alter your display for that field by placing them in the Text box.

The title field will get double quotes around it and text behind it.

 

This is the output of the rewritten text field using the replacement patterns above.

If you want to rewrite the output of the field into a link, you can use Output this field as a link option.  This will give you lots of options that you can experiment with.

There are additional options for you to experiment with like strip HTML tags and convert newlines to br tags.  These options are not used as much, but worth investigating.  They may solve your problem in the future.