pmiranda
pmiranda

Reputation: 8470

Read object from array

Using print_r($session)) I can see my session data like this:

(
    [code] => 123
    [profile] => 'Admin'
    [data] => Array
        (
            [0] => stdClass Object
                (
                    [Info] => 555
                )
        )
)

Ok, so if I want to print in screen via twig the profile, this works

{{ app.session.get('profile') }}

And I get Admin which is correct. But how can I read the Info ? I thought that something like

{{ app.session.get('data[0].Info') }}

would work but I'm getting blank data. If I use {{ dump(data[0].Info) }} shows the correct info (555).

Upvotes: 2

Views: 41

Answers (1)

DarkBee
DarkBee

Reputation: 15583

You have to do it step-by-step. First pull the correct variable, afterwards treat it like an array:

{{ app.session.get('data')[0].Info }}

Upvotes: 3

Related Questions