Token replacement doesn't work when empty

Created on 25 August 2023, almost 2 years ago
Updated 3 January 2024, over 1 year ago

Problem/Motivation

Subscribers can enter first name, last name and job title. The fields are named

field_firstname, field_lastname, field_jobtitle.

I built a greeting line
Welcome, [simplenews-subscriber:field_jobtitle] [simplenews-subscriber:field_lastname]!

Sending the newsletter, only fields wich have content are substituted, maybe resulting in a line like
Welcome, Director Jones!

However, if a field hasn't been filled in, the token is printed:
Welcome, [simplenews-subscriber:field_jobtitle] McNeal!

This worked since I send mail with simplenews, at least for a decade, but it is broken with 3.0.0-beta5. It may be broken since a much earlier release, as I didn't debug token replacement for a while.

Steps to reproduce

I spotted the issue with code which used to work for at least three years, and I set up a newsletter/subscription on a 9. for development after spotting this issue.

Proposed resolution

Check for the content of a field and don't output anything in case it's empty. Earlier versions outputted a space, which lead to adjacent spaces when there were no replacements, which looked odd.

Final Question

It would be nice to run Views on the subscriber list and output to simplenews. This would allow the use of well proven views methods to create personalized newsletter which are then themed and send by simplenews / mailer. Is this possible already, is it in consideration or does it remain just a pipedream I began dreaming a decade ago?

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇦🇹Austria nofue

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

Comments & Activities

Production build 0.71.5 2024