Make twig or conditional rendering work

SoftTimur

Member
Hello,

I'm trying to make conditional rendering work. It seems that twig is supposed to achieve that. I have enabled engine in the backend:

Screenshot 2024-11-27 at 14.57.25.png

Then in the campaign template page, I write the follows where `WECHAT` is a custom field:

Screenshot 2024-11-27 at 14.58.16.png

However, the test email I recieved is as follows. As you can see, the if statement was not interpreted.

Screenshot 2024-11-27 at 14.58.56.png

Does anyone know how to make twig or conditional rendering work here?

Thank you
 
Does anyone know how to make twig or conditional rendering work here?
You need to add your custom tags in [] and use "" instead '' , like in bellow example:


Code:
{% if [WECHAT] == "" %}
  Empty
{% else %}
  Not empty
{% endif %}
 
You need to add your custom tags in [] and use "" instead '' , like in bellow example:


Code:
{% if [WECHAT] == "" %}
  Empty
{% else %}
  Not empty
{% endif %}
Thank you for your reply. I tried your code, the custom field was interpreted but the if statment was not interpreted. Here is the code in the template:

Screenshot 2024-11-27 at 16.08.49.png
Here is the test email I received:
Screenshot 2024-11-27 at 16.08.58.png
 
Hello,

try to delete entire template and recreate it , most probably you have bad html inside and this ca be a cause that twig not working correctly.
 
Hello,

try to delete entire template and recreate it , most probably you have bad html inside and this ca be a cause that twig not working correctly.
I started a new simple campaign. I realized that when "Only plain text" was "Yes", the twig did work; when "Only plain text" was "No", the twig did NOT work.

Screenshot 2024-11-27 at 16.55.40.png

If I clicked `Source`, I saw the following html

```
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>Hello, {% if [WECHAT] == "" %} Empty WeChat {% else %} Not empty WeChat {% endif %} Bye [DIRECT_UNSUBSCRIBE_LINK]</body>
</html>
```

If I toggled GrapesJS template builder and viewed code, I saw the following html

```
<body style="box-sizing: border-box; margin: 0;">Hello, {% if [WECHAT] == "" %} Empty WeChat {% else %} Not empty WeChat {% endif %} Bye [DIRECT_UNSUBSCRIBE_LINK]
<title>
</title>
</body>
```

My future campaigns will contain images, I need "Only plain text" to be "No". Do you know why twig did not work in this simple case?
 
Last edited:
Back
Top