Drupal is a registered trademark of Dries Buytaert
drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

markup_twig

90 sites No security coverage
View on drupal.org

Extension module to Markup Field module to use Twig in Markup fields.

How to use:

  1. Install this module like any other, see this documentation.
  2. Set 'Administer markup fields' permission for trusted roles
  3. Add a markup field to your entity
  4. Use twig syntax in the markup field
  5. Select "Markup Twig" as
    • Field widget (admin/structure/types/manage/XXX/form-display)
    • Field formatter (admin/structure/types/manage/XXX/display) in your field administration. Otherwise twig will be rendered as plain text.

Dependencies:

Typical use-cases & examples

Still TODO, see #3026770: Provide typical examples and use-cases on the module page
You may help and suggest snippets:

Display all available twig variables

{{ kint() }}
Requires twig debug to be enabled, see Debugging Twig templates
We're planning to provide a smarter solution: #3026576: Integrate with codemirror_editor

Get URL from file / image field

{{ node.field_name.0.entity.uri.value }}
("node" may be "user", "term", ... it's the dynamic name of the entity type)

Render image from image field (requires Twig Tweak)

{{ node.field_name.0.entity.uri.value|image_style('thumbnail') }}
("node" may be "user", "term", ... it's the dynamic name of the entity type)

Render an other field from the entity (requires Twig Tweak)

{{ node.field_name|view }}
("node" may be "user", "term", ... it's the dynamic name of the entity type)

Render entity title

{{ node.title }}
("node" may be "user", "term", ... it's the dynamic name of the entity type)

Extensions

Favourite: You may want to use the famous Twig Tweak module to enhance twig with further filters and functionalities, e.g. {{ node.field_tags|view}} (see https://www.drupal.org/docs/8/modules/twig-tweak/cheat-sheet-8x-2x)
Alternatively: Twig Render This may be very useful if you'd like to render a field from the given entity by simply writing: {{ node.field_tags | renderThis }} (see https://www.drupal.org/docs/8/modules/twig-render-this/tutorial)
Additionally: Twig Extensions: Adds further filters and functionalities from the twig extensions lib:

Alternatives:

  • Field Token Value: Could be used for simple cases where Computed Field is too heavy.
  • Computed field: The sladge hammer for dynamic fields
  • Extra field: Provides extra fields programmatically via plugin.
    Extra fields do not store data and do not have a field widget. Extra fields typically combine existing entity data and format it for display.
  • Twig field: Provides twig syntax field in the entity create / edit form (like body field, not on meta-level).
  • Filter Twig: Provides an input filter with twig support

Important:

This module adds a permission "Administer markup fields". Do not allow untrusted users to edit Twig templates as it may cause security implications. Hopefully this functionality will be integrated into Markup field one day #3026539: Add "administer markup fields" permission.

Development proudly sponsored by German Drupal Friends & Companies:

webks: websolutions kept simple (https://www.webks.de)
and
DROWL: Drupalbasierte Lösungen aus Ostwestfalen-Lippe (OWL), Germany (https://www.drowl.de)

Activity

Total releases
1
First release
Jan 2025
Latest release
1 year ago
Release cadence
Stability
0% stable

Releases

Version Type Release date
8.x-1.0-rc7 Pre-release Jan 23, 2025