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

General project discussion. NOT for help questions.
Post Reply
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

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

Post 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
Last edited by blackhawk on Tue Apr 30, 2013 9:04 pm, edited 1 time in total.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

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

Post 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.
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

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

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post by calguy1000 »

Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

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

Post by blackhawk »

I feel like an idiot. Sorry and thank you for helping me out.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

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

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Post Reply

Return to “General Discussion”