问题
I am using dust 1.1.1. I've tried nesting the @size help inside of an @if but that broke.
Another trick to it is once I've determined the length is greater than one I then want to iterate through the array.
回答1:
The Dust grammar does not allow a helper to be used inside another helper, except in the body.
Instead, I would try something like this:
{#myArray}
{@gt key=$len value=1}{.}{/gt}
{/myArray}
This will only output the value of the element in the array if the length of the array ($len
) is greater than 1.
回答2:
My workaround for this was:
{?myArray[1]}
{!Do greater than one stuff!}
{/myArray[1]}
来源:https://stackoverflow.com/questions/17220800/using-dustjs-how-do-i-show-a-block-of-code-when-an-arrays-size-is-greater-than