Sunday, June 10, 2018

How to show a section if a list if not empty in Moustache?

Leave a Comment

This is a question about Mustache syntax. I'm using clostache but I don't think that makes a difference.

The 'Section' operator appears to be overloaded to mean

if the bound value is boolean, it means if, but if it's a list it means loop

What if I want to show a section if a value is non-false but not iterate? For example (creating an example operator with a % character)

{{%people}} <p>There are people. Here they are:</p> <ul> {{#people}}<li>{{name}}</li>{{/people} {{/people}} 

This seems like a very common use case but I can't obviously see the syntax for it. How do I accomplish this?

1 Answers

Answers 1

Unfortunately what you've described is not possible. In your JS code you must create a new section for the title and set it to true if the length of people is greater than 0.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment