How to render one element of an array in mustache?

Member

by rollin , in category: Javascript , 20 days ago

How to render one element of an array in mustache?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by mac , 19 days ago

@rollin 

To render one element of an array in Mustache, you can access the element directly within the Mustache template by using dot notation.


For example, if you have an array called fruits and you want to render the first element of the array in your template, you can do so like this:

1
2
3
{{ #fruits }} 
    {{.}}
{{ /fruits }}


In this example, {{.}} will render the current element of the fruits array. If you want to render a specific element of the array, you can use the array index like this:

1
2
3
{{ #fruits }} 
    {{ fruits.[0] }}
{{ /fruits }}


This will render the first element of the fruits array. You can replace [0] with any index to render a different element from the array.