javascript - nunjucks ternary if expression - Stack Overflow

I'm using nunjucks as a templating engine in my application and can't seem to get the block t

I'm using nunjucks as a templating engine in my application and can't seem to get the block to display at all when I apply more than two conditions e.g.

{{ "true" if foo else "false" }}

The above example works just fine, however the following does not:

{{ "message one" if condition_1 else "message two" if condition_2 else "default" }}

The error message I get tells me that a comma is missing but no matter where I add one it continues to tell me a comma is missing. Is there a way to get this to work? I could solve this with if tags, but I'd have to then duplicate the whole block which doesn't sound like a good solution.

I'm using nunjucks as a templating engine in my application and can't seem to get the block to display at all when I apply more than two conditions e.g.

{{ "true" if foo else "false" }}

The above example works just fine, however the following does not:

{{ "message one" if condition_1 else "message two" if condition_2 else "default" }}

The error message I get tells me that a comma is missing but no matter where I add one it continues to tell me a comma is missing. Is there a way to get this to work? I could solve this with if tags, but I'd have to then duplicate the whole block which doesn't sound like a good solution.

Share Improve this question asked Mar 24 at 21:23 Haggishunt56Haggishunt56 1112 silver badges10 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1
{{ "foo" if cond1 else ("bar" if cond2 else "baz") }}

should work according to this post.

Haven't tried it myself though

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744227765a4564092.html

相关推荐

  • javascript - nunjucks ternary if expression - Stack Overflow

    I'm using nunjucks as a templating engine in my application and can't seem to get the block t

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信