On this page
Rewrite the output of a view field
Last updated on
12 April 2024
You can configure a field in a view to display information that is different from the actual data in the field. By using tokens, you can enhance the field with dynamic content from the database.
- Navigate to the edit screen for a view (for example, admin/structure/views/view/MYVIEWNAME/edit).
- In the Fields section, click a field. The Configure Field dialog box displays.
- Click Rewrite Results.
- Enable any of the following options:
- Override the output of this field with custom text You can replace the field with custom text which may include a subset of HTML. When this option is enabled, a list of tokens is displayed (expand the Replacement Patterns section) which you can use to dynamically add data to the custom text.
- Output this field as a custom link You must enter the link path. You can also configure various options for how the link will be displayed.
- Trim this field to a maximum number of characters Enter the maximum number of characters that will be displayed.
- Strip HTML tags When this option is enabled, all HTML tags will be stripped. You can also specify certain tags to keep.
- Remove whitespace If this option is enabled, all whitespace at the beginning and the end of the output will be removed.
- Convert newlines to HTML <br> tags If this option is enabled, all newline characters (e.g. \n) are converted into break tags.
- Click Apply.
Twig
You can use Twig for calculations or comparing values in fields with Rewrite result. Note that you need to use the raw value (in this example it would be field_rank__value) or convert the object into a string by adding |trim to the end of the field value:
{% if field_rank|trim > 20 %}
Value is higher than 20
{% endif %}The example tokens:
{{ field_rank }}== Rank{{ field_rank__value }}== Raw value
See Math in rewrite result in Views for more.
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.