drupal|April 11, 2020|1 min read

Drupal 8 Views - How to merge two fields by hiding another field

TL;DR

Use the 'Rewrite results' option in Views to combine two fields using token replacement, then exclude the secondary field from display.

Drupal 8 Views - How to merge two fields by hiding another field

Introduction

You have a view with 4-5 fields to display. Suppose, there are two fields: payment amount and currency. Where currency can be INR and USD. I want to show fields in a table, don’t want to show these two fields as separate.

I want to show these two fields as one. Example:

ID   Name   Amount
 1   ABC    10 USD
 2   XYZ    700 INR

I hope you get the above example, otherwise if the two fields will be separate. I will have 4 fields in above table.

Views Settings

Lets see how we can configure our view.

  • Goto your view
  • Goto fields settings
  • Click on the field you dont want to display as a separate field. In my example, currency is the field
  • Check on “Exclude from display”. This will be hidden now
  • Now, Rearrange your fields
  • Move that hidden field at top. (This will allow us to show this field value as token in other field configuration)
  • Goto that field with which you want to append our hidden field. In my example, its Amount
  • Click on Rewrite results
  • Override the output of this field with custom text
  • You can see “Replacement Patterns”
  • You can see your hidden field there
  • Put following (my example):
{% raw %}
{{ amount }} {{ currency }}
{% endraw %}

Drupal merge fields

Related Posts

How to connect Php docker container with Mongo DB docker container

How to connect Php docker container with Mongo DB docker container

Goto your command terminal. Type: This will expose port: 27017 by default. You…

A Practical Guide on how to to create your own git command alias

A Practical Guide on how to to create your own git command alias

Introduction In this guide, We will learn on how to create some handy command…

How to Solve Spring Okta/Saml issue of SAML message intended destination endpoint did not match the recipient endpoint

How to Solve Spring Okta/Saml issue of SAML message intended destination endpoint did not match the recipient endpoint

Introduction I was trying to integrate Okta with Spring, and when I deploy the…

A Practical Guide on how to work with Git log command and history

A Practical Guide on how to work with Git log command and history

Introduction In this post, we will see ways to look at git history logs. For…

How to Use Google Fonts in Website design with Bootstrap

How to Use Google Fonts in Website design with Bootstrap

If you are using Bootstrap, the default font that comes with the package is…

Youtube API in NodeJs, Usage with Example

Youtube API in NodeJs, Usage with Example

This library is ES6, promise compatible. Or, in your package.json file, include…

Latest Posts