variable variable name

56 views
Skip to first unread message

v.

unread,
Apr 23, 2020, 12:16:03 PM4/23/20
to Fat-Free Framework
I have a session variable that I need to output in a view.
Let's say the key is
@SESSION.result.parent_age

A view is included dynamically where "parent" is set in the calling view, like this:
<set famMember="parent" />
<include href="age.htm" />

In age.htm I need to ouput the resulting @SESSION.result.parent_age, but I fail to do so.

I have tried
<set age="@SESSION.result"{{ @famMember}}"_age" /> //also tried with concatenating dots
{{ @age}}
and
<set age="{{ '@SESSION.result' .  @famMember. '_age'}}" />
and all combinations with or without colnos and concatenating dots, but I always get a 500 error
 
{{ @SESSION.result.@famMember.'_age' }}

outputs 'Arrayparent_age'. I understand why this would happen, but how do I get the correct value?

To be clear: in this particular case there are 40 famMembers with their corresponding _age, so I really need to get the values dynamically.

richgoldmd

unread,
Apr 23, 2020, 1:18:32 PM4/23/20
to Fat-Free Framework
Hi!
You are close...

You could try:

<set age="{{ @SESSION.result[@famMember . '_age'] }}">



or directly:

{{ @SESSION.result[@famMember . '_age'] }}

because you are building the index into the array dynamically.
I'm assuming @SESSION.result is an associative array.

v.

unread,
Apr 23, 2020, 2:51:23 PM4/23/20
to Fat-Free Framework
Thanks yet again doc, you're a life saver.
The amount of beers I owe you (and also ved) will destroy your liver :)

richgoldmd

unread,
Apr 23, 2020, 3:10:43 PM4/23/20
to Fat-Free Framework
No worries v! Glad to help.


Reply all
Reply to author
Forward
0 new messages