Twig suppport in templates.

Created on 30 June 2025, about 1 month ago

Problem/Motivation

I needed to embed a view into my message template. There is a module which allows views to be embedded as token and that works with Message tpls.

Token format is something like [view:myview:myview-display:arg1:arg2:etc]. But my arg1 in most cases is NID. so maybe this: [view:myview:myview-display:[node:nid]], but sadly Drupal's token system doesnt handle recursive tokens.

So then i thought about twig support. Had numerous other instances when some simple conditional logic wold have been create in a mail template without having to making custom tokens each time this came up. Plus i had recently added tiwg support to the FillPDF module and discovered how easy it is (2 lines of code). So i did up this simple patch to add twig support to message templates. It runs before token processing, so my solution above is simply this:

[view:myview:myview-display:{{ node.id }}] and this works perfectly. But of course much more complex conditional case can now be handled in mail templates as well.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇨🇦Canada liquidcms

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024