Reputation: 1707
Am new to dust template and to know the solution for this problem
I would like to iterate through this view context and get only the relative and friends arrays first item.
{
Relative: "ravi",
friends: [
{ name: "Moe", age: 37 },
{ name: "Larry", age: 39 },
{ name: "Curly", age: 35 }
]
}
Upvotes: 0
Views: 1851
Reputation: 5609
You can accomplish using the @eq
helper, available in the LinkedIn fork of Dust.
{Relative}{~n}
{#friends}
{@eq key=0 value="{$idx}" type="number"}
{name} {age}
{/eq}
{/friends}
You still loop through the entire array, but only output name and age if the array index ($idx
) is 0
.
Upvotes: 1