Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

View Mode Twig Field

No security coverage Drupal 10–11
View on drupal.org

This module allows you to add custom fields to your content displays that render using Twig code. You can use these "Twig Fields" to combine existing data, add custom links, or create formatted output without needing to add actual fields to your content types.

View Mode Twig Field provides a flexible way to inject custom Twig-rendered content directly into entity view modes via the Drupal Field UI.

Introduction

Have you ever needed a "pseudo-field" to display a combination of entity values, a custom link, or a wrapper without creating a physical field in the database? This module allows you to create and manage these "Twig Fields" directly within the Manage Display tab of any entity.
Each Twig field is managed via an inline settings accordion, allowing for quick edits to labels and Twig logic directly within the field list.

Requirements

  • Drupal 10.3 or 11.x
  • Field UI (Core module)

Installation

  • Place the view_mode_twig_field module folder in your modules/custom directory.
  • Navigate to Extend in your Drupal admin menu.
  • Locate View Mode Twig Field, check the box, and click Install.

Alternatively, via Drush: drush en view_mode_twig_field

Configuration

To create and use Twig fields:

  • Navigate to the Manage Display tab of any entity (e.g., Admin > Structure > Content types > Article > Manage display).
  • Scroll to the bottom and click the "Add Twig Field" button.
  • A new field (initially disabled) will appear in the list named "New Twig Field".
  • Move the field from the Disabled section into a visible region (like "Content").

Open the Settings Accordion: Locate your Twig field in the list. You will see a "Twig Settings" details/accordion element directly in the field row.

Configure the field:

  • Label: Change the name of the field as it appears in the UI.
  • Twig Code: Enter your template logic. You have access to the entity object.
  • Delete: Check this box if you wish to remove the field on the next save.

Click Save at the bottom of the display form to apply your changes.

Usage Examples

Concatenating Fields

<div class="custom-header">
  {{ entity.field_first_name.value }} {{ entity.field_last_name.value }}
</div>

Accessing Parent Entities

{# Display the label of a referenced taxonomy term #}
{{ entity.field_category.entity.label }}

Known Limitations

Shared Bundle Definitions

When a Twig Field is created, it is registered at the bundle level. This means the field will appear in the "Manage Display" list for all view modes of that bundle (e.g., both "Teaser" and "Default" view modes of a Page content type will show the field).

Independent Values

While the field definition is shared across view modes, the settings (Twig code and Label) remain independent per view mode. You can have different code for the Teaser than you do for the Full display.

Initial Save

Fields must be moved out of "Disabled" and the form saved once before the accordion settings fully initialize.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Feb 2026
Latest release
6 months ago
Releases (12 mo)
3 ▲ from 0
Maintenance
Slowing

Release Timeline

Releases

Version Type Core Release date
1.0.1 Stable 10–11 Feb 6, 2026
1.0.0 Stable 11 Feb 2, 2026
1.0.x-dev Dev 10–11 Feb 2, 2026