defunkt/mustache — Issue #118: Add NOT empty check
Author: jtreminio
Created: 2011-11-15 06:33:41+00:00
State: open

Would like to propose that a NOT EMPTY section check be added.

Currently this checks if empty:

`{{^empty_string}}foo{{/empty_string}}`

But if we want to check if element is NOT empty, we have no other choice than using `{{#check}}foo{{/check}}`, but this has the side effect of iterating through the element if it's an array.

An example where this would be an issue would be in an HTML menu.

Here's what we want HTML to look like:

````html
Home

Posts

All Posts

Add New

Pages

All Pages

Add New

````

You can't currently test if there are sublinks to each section without iterating over the results, so you can't print out `

` and `

` a single time - it would print out as many times as there are links in the array that contains the sublinks.

Using a NOT EMPTY check would alleviate this problem:

````
{{@sublinks}}

{{#sublinks}}
{{name}}
{{/sublinks}}

{{/sublinks}}

I've extended the PHP Mustache class and it's exactly 7 lines of code. I don't know Ruby but I can't imagine it being any different.

Thanks!