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.
1 Answer
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
评论列表(0条)