user1077250
user1077250

Reputation: 155

Access a single element of the array within twig

I'm using symfony2 and twig in my view. I'm sending an array to the view which has been created using from a mysql query, not using the symfony entity framework: $claims_summary_table = $statement->fetchAll();

I can dump this in the view...

{{ dump(claims_summary_table) }}
array:1 [▼
         0 => array:11 [▼
                         "claim_status" => "Open"
                         "claim_id" => "101"
                         "claim_reference" => "BALLINGM"
                         "loss_date_from" => "2015-06-02"
                         "loss_catastrophe_name" => "Fire"
                         "loss_value" => "2000.00"
                         "total_payments" => "300.00"
                         "total_reserve" => "2000.00"
                         "claim_file_closed" => null
                         "last_seen_date" => "2016-04-20 11:20:25"
                         "last_seen_by" => "2"
                         ]
                         ]

but I just want to access one element, I just want to access "Open".

I have tried {{ claims_summary_table.claim_status }}

The only way I can access the single element is if I use a { for.....}.

How can I just get one element?

Upvotes: 0

Views: 249

Answers (2)

Matteo
Matteo

Reputation: 39390

If you need to access the first element of the sub-array you can use the following.

{{ claims_summary_table[0][0]. claim_status }}

and

{{ claims_summary_table[0][0]. claim_id }}

Otherwise you need to iterate and looking for the record with the claim_stauts open

Upvotes: 2

Otto
Otto

Reputation: 450

You can access the values by array key, in your case:

{{ claims_summary_table[0]. claim_status }}

Upvotes: 0

Related Questions