我正在尝试使用 SendGrid 中的把手设置字符串匹配。据我了解,您只能将 if 语句与布尔值一起使用,因此我尝试通过 {{equals}} 来代替。这工作正常,但我然后尝试将那个“东西”注入到结果中。我在下面得到的结果是,如果 data = TEXT 那么电子邮件会显示“This is some TEXT”
{{#equals thing "TEXT"}}
This is some {{insert thing}}
{{/equals}}
在 {{equals}} 车把外面使用 {{insert thing}} 没问题,但在里面就不行了返回任何东西。我只是得到“这是一些”
有谁知道这是否受支持或者是否有更好的方法?
谢谢。
I'm trying to set up a string match using handlebars in SendGrid. As I understand it, you can only use the if statement with booleans so I'm trying via {{equals}} instead. This works fine but I'm then trying to inject that 'thing' into the result. The result I'm after in the below is that if the data = TEXT then the email reads "This is some TEXT"
{{#equals thing "TEXT"}}
This is some {{insert thing}}
{{/equals}}
Using {{insert thing}} outside the {{equals}} handlebar is fine but when inside it doesn't return anything. I just get "This is some"
Does anyone know if this is supported or if there is a better way?
Thanks.
发布评论
评论(1)
我不完全确定如何解释它,但似乎在车把的块内有一个新的范围。这对于循环很有效,其中范围是循环中的当前项,但对于范围似乎不包含任何内容的条件则不太有效。您可以使用
@root
关键字,因此您可以使用它从块外部获取某些内容。在这种情况下,您可以像这样使用它:I'm not entirely sure how to explain it, but it seems that within blocks in handlebars there is a new scope. This works well for loops, where the scope is the current item in the loop, but less well for conditionals where the scope doesn't seem to include anything. You can get back to the root scope using the
@root
keyword though, so you can use that to get something from outside of the block. In this case, you can use it like this: