json 中的 SendGrid Handle bars 变量在第二次使用时不显示

SendGrid Handle bars variable in json not show up when used a second time

我在 SendGrid 中有这个 handle bars 语句。使用变量 taskCount 时,该值仅在 greaterThan 块中使用。另外 2 次使用它似乎是空的。

这是json数据

{
    "Username":"ChampCbg",
    "JoinedAt":"12/1/2020",
    "DaysSinceJoined":"20",
    "taskCount":5
}

这是带车把的声明

{{#greaterThan taskCount 0}} 
Congrats on starting {{insert taskCount "default=1"}} task{{#greaterThan taskCount 1}} (s){{/greaterThan}} and taking the first small step. 
{{else}}
You have not started a task yet. What are you waiting for? It has been {{DaysSinceJoined}} days since you joined on {{JoinedAt}}. 

You have missed {{DaysSinceJoined}} days where you could been making Small Steps towards the dreams of you better tomorrow. 
{{/greaterThan}}

这是最终结果

Hello ChampCbg!

Congrats on starting 1 task and taking the first small step.

Don't let another day pass you by. Start designing you vision board today.

结果显示 greaterThan 块选择了正确的语句,但是下次使用 taskCount 时选择了默认值和空值。

这是什么原因?

此处为 Twilio SendGrid 开发人员布道师。

老实说,我认为您的模板会像您编写的那样工作。但我试过了,但没有成功(不是我不相信你,我只是必须这样做才能弄清楚该怎么做!)。

因此,处理此问题的方法是在 greaterThan 条件(或其他条件)中使用 @root object 引用数据中的变量。

试试这个作为你的模板:

{{#greaterThan taskCount 0}} 
Congrats on starting {{insert @root.taskCount "default=1"}} task{{#greaterThan @root.taskCount 1}} (s){{/greaterThan}} and taking the first small step. 
{{else}}
You have not started a task yet. What are you waiting for? It has been {{@root.DaysSinceJoined}} days since you joined on {{@root.JoinedAt}}. 

You have missed {{@root.DaysSinceJoined}} days where you could been making Small Steps towards the dreams of you better tomorrow. 
{{/greaterThan}}