Tony Topper
Tony Topper

Reputation: 411

Using dustjs how do I show a block of code when an array's size is greater than one

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.

Upvotes: 1

Views: 1160

Answers (2)

Anushka Munasinghe
Anushka Munasinghe

Reputation: 11

My workaround for this was:

{?myArray[1]}
    {!Do greater than one stuff!}
{/myArray[1]}

Upvotes: 1

smfoote
smfoote

Reputation: 5609

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.

Upvotes: 1

Related Questions