You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know this may be frowned upon, but in the JS implementation you can do
{{#items.length}}
stuff rendered if items is non-empty
{{/items.length}}
Several other implementations have some similar way of checking this.
This is not really spec compliant, and I know Mustache is supposed to be logic-less, but it's very useful if you want to render a block only if an array is non empty. A prime example is if you want to render a HTML table, but only if it would contain any rows, then you could do:
and then check for items_list, or by introducing a has_items alongside items.
It would be very nice if qt-mustache could support .length or similar, for those of us who know we'll be using qt-mustache and don't care too much about interoperability.
The text was updated successfully, but these errors were encountered:
If there is a widely supported pattern across several common Mustache implementations I think I would be OK with supporting this. See #21 (comment) for notes on where to implement it.
Alright, as far as I know, there isn't really :/ I understand your reservations and will close this for now. Lets hope the Mustache spec is updated some day to include such a feature. For now I'll use a has_xyz field.
I know this may be frowned upon, but in the JS implementation you can do
Several other implementations have some similar way of checking this.
This is not really spec compliant, and I know Mustache is supposed to be logic-less, but it's very useful if you want to render a block only if an array is non empty. A prime example is if you want to render a HTML table, but only if it would contain any rows, then you could do:
You don't want to render the enclosing
<table><tbody>...</tbody></table>
if the table would be empty.This is not possible without a
.length
-type of feature, short of wrapping your list under an ugly dummy key, e.g:and then check for
items_list
, or by introducing ahas_items
alongsideitems
.It would be very nice if
qt-mustache
could support.length
or similar, for those of us who know we'll be usingqt-mustache
and don't care too much about interoperability.The text was updated successfully, but these errors were encountered: