Page 1 of 1

[SOLVED]How do we access nested array items via smarty?

Posted: Tue Apr 30, 2013 7:34 pm
by blackhawk
It's been a long time since I've done this and I am trying to get back into the swing of things. Within SMARTY, I am able to view and access all of my basic template variables with..

Code: Select all

{get_template_vars}
and even be more specific by looking up things like $fields from the Form Builder module...

Code: Select all

<pre>
{$fields|print_r}
</pre>
But how do we access nested arrays, for example my custom $fields array in Form Builder contains....

Code: Select all

[sdatepicker] => stdClass Object
        (
            [display] => 1
            [required] => 0
            [required_symbol] => 
            [css_class] => session-block sdatepicker
            [helptext] => 
            [field_helptext_id] => fbrp_ht_40
            [valid] => 1
            [error] => 
            [hide_name] => 0
            [has_label] => 1
            [needs_div] => 1
            [name] => Next Appointment Date
            [input] => Array
                (
                 ...

...And all I want to do is remember how to access value for [name] and array values for [input].

Thanks for any advice

Re: How do we access nested template array items via smarty?

Posted: Tue Apr 30, 2013 8:18 pm
by velden
Search for 'smarty multidimensional array' in Google.

It's something like $nameofarray->secondarray.value

but I could be wrong with '->', maybe that should also be a dot. Think you can find it via Google.

Re: How do we access nested template array items via smarty?

Posted: Tue Apr 30, 2013 8:49 pm
by blackhawk
Thanks. All sources are pointing me to use either a {foreach} or {section} loop to access inner array data. Is that normal in my case?

Re: How do we access nested template array items via smarty?

Posted: Tue Apr 30, 2013 8:52 pm
by calguy1000

Re: How do we access nested template array items via smarty?

Posted: Tue Apr 30, 2013 9:03 pm
by blackhawk
I feel like an idiot. Sorry and thank you for helping me out.

Re: How do we access nested template array items via smarty?

Posted: Wed Oct 02, 2013 4:15 pm
by Rolf