Question

I am trying to put some logic into user registration welcome emails. Simple "if-then" logic, based on tokens.

The tokens I use show up as expected, but both twig and php code gets sent as plain text.

Can I somehow make twig or php code execute before the email is sent to the new user?


UPDATE, to make the question more specific:

I have token module enabled.

I am trying to add this logic to the welcome email sent to new users at "/admin/config/people/accounts":

{% if [user:field_marketing_package] == "Yes" %}
<p>Marketing selected</p>
{% endif %}

The [user:field_marketing_package] field is filled out at user registration.

I would like to add logic like this. If I have the above twig code in the message, it just gets sent as plain text and does not execute.

Twig or php or any other solution is fine as long as I can include the token in the if statement.

Can you point me to the right direction?

Was it helpful?

Solution

Pretty ugly, but I have a solution. Please post if you have a better one that can be applied for more use cases.

So I installed the https://www.drupal.org/project/computed_field module.

I added a hidden computed filed to my user registration form with my logic.

Then I used the token module to include the value of that computed field in my user welcome email.

It does the job, but again, it is pretty ugly. Hopefully this helps someone until someone posts a more direct solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top