Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mustache

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?

like image 893
Joe Avatar asked Aug 29 '14 13:08

Joe


1 Answers

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.

like image 141
Elliot B. Avatar answered Oct 16 '22 12:10

Elliot B.