Re: {php} tags and multidimensional arrays in smarty.
| From: | Rob Adams | Date: | Wed, 15 Dec 2004 21:05:58 +0000 |
| Subject: | Re: {php} tags and multidimensional arrays in smarty. | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12046@lists.php.net to get a copy of this message | ||
"Matthew Weier O'Phinney" <matthew@garden.org> wrote in message
news:slrncs0hif.hal.matthew@webmaster.garden.org...
>* Rob Adams <rob_adams@hotmail.com>:
>> I have a situation where I need to display a variable number of shipping
>> address forms, depending on user input. Since there is no built in for
>> or
>> while loop, I used {php}tags to setup a loop through the address forms.
>
> Why exactly don't the {foreach} and/or {section} constructs work for
> you? In particular, the {foreach} construct even creates iterators so
> you can keep track of where you are in a loop (i.e., the index).
Thanks for replying. The reason foreach and section won't do is because I
have no array (and don't really want to create one just for a loop.)
Anyway, this part isn't really the problem. The loop works just fine.
>
>> Everything is working great, except one part:
>> {select name=sstate test=$ship.$addrcnt.state}
>>
>>
>> This is a custom function I've made, to help put the text 'selected' in
>> the
>> right spot on select/option fields. Anyway, you can see what I'm trying
>> to
>> do here, but it obviously doesn't work. Any way I can make this work?
>> Below is the line in context:
>>
>> <select name="ship[{$addrcnt}][state]"
>> class="listbox" >
>> <option value=""> Select State </option>
>> {select name=sstate test=$ship.$addrcnt.state}
>
> Just a haphazard guess here -- does {select} return 'selected' or '',
> depending on the test? If so, the above line seems like it should be
> within an <option> element.
You seem to have taken this out of context just a little... This {select}
you pasted above just sets a value to be tested against (what the currently
selected value SHOULD be.) You left off the loop through the <options>
which does have a {select} call inside the <option> tag. The first one sets
it up, and the second one either outputs 'selected' or ''.
The only real problem I'm having is with the syntax:
$ship.$addrcnt.state.
Just doesn't work like I thought it would; and I can see now why, and that
it shouldn't, but can't figure how it needs to be.
Any ideas? Thanks.
-- Rob