1

I have an array like:

Array
(
    [0] => Array
        (
            [title] => Title 1
            [value] => Value 1
            [id] => 1428735262
        )

    [1] => Array
        (
            [title] => Title 2
            [value] => Value 2
            [id] => 2428735262
        )

    [2] => Array
        (
            [title] => Title 3
            [value] => Value 3
            [id] => 3428735262
        )

)

With mustache I am able to iterate overall of them using:

{{#values}}
    <h1>{{title}}</h1>
    {{{value}}}
{{/values}}

But what if I only want to show specific value, for example only second element of the array (one with Title 2)?

I tried like:

{{#values}}
{{#2428735262}}
    <h1>{{title}}</h1>
    {{{value}}}
{{/2428735262}}
{{/values}}

and:

{{#values.2428735262}}
    <h1>{{title}}</h1>
    {{{value}}}
{{/values.2428735262}}

But none worked. Does anyone know how to get specific item from array ?

PS. I am using PHP version of mustache. Thanks

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63
Dev01
  • 4,082
  • 5
  • 29
  • 45

1 Answers1

1

You can use this:

{{values.1.value}}

Read more at:

https://github.com/bobthecow/mustache.php/wiki/Variable-Resolution

Adrian Cid Almaguer
  • 7,815
  • 13
  • 41
  • 63