RE: Re[2]: [SMARTY] foreach/assign conflict? dropping last value
| From: | Josh Johnson | Date: | Tue, 15 Oct 2002 14:39:34 +0000 |
| Subject: | RE: Re[2]: [SMARTY] foreach/assign conflict? dropping last value | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6147@lists.php.net to get a copy of this message | ||
Ok, you can't use a smarty variable inside of a string like that... so
your assign call just isn't working... You'll need to assemble the
variable name some other way, and it should work... I've used {capture}
in the past with no problems:
{foreach item=sock from=$socks key=key}
{capture name=sock_isbn}sock_{$key}{/capture}
{assign var=$smarty.capture.sock_isbn value=$sock}
{/foreach}
That should work the way you intend... I'm sure there are other ways,
I'm not sure how efficient the capture function is since it uses the
output buffering functions of php, but like I said, I haven't had any
problems.
-- Josh
-----Original Message-----
From: guido [mailto:sguido@rogers.com]
Sent: Tuesday, October 15, 2002 10:30 AM
To: Josh Johnson
Cc: 'Smarty'
Subject: Re[2]: [SMARTY] foreach/assign conflict? dropping last value
JJ> A few questions:
JJ> Why aren't you using $smarty.post?
Because the data isn't a pure post, it's coming from another module
that's setting the loop data to $post_vars array.
JJ> When are you trying to access that assigned variable? (the
order_$key
JJ> one)? Inside of the foreach loop, or outside?
The assign is going on inside the loop as shown.
And access is going on outside the loop, but it also doesn't work
inside the loop either.
JJ> -- Josh
JJ> -----Original Message-----
JJ> From: guido [mailto:sguido@rogers.com]
JJ> Sent: Tuesday, October 15, 2002 12:03 AM
JJ> To: Smarty
JJ> Cc: Martin Kjeldsen
JJ> Subject: [SMARTY] foreach/assign conflict? dropping last value
JJ> ok this is a weird one ...
JJ> what I'm doing is taking a HTTP_POST_VARS and looping through them,
JJ> setting them as hidden form fields and then setting them as
variables:
JJ> {foreach key=key item=item from=$post_vars}
JJ> {assign var="order_$key" value="$item"}
JJ> <input type="hidden" name="{$key}" value="{$item}"> {*
JJ> FORM *}
JJ> {/foreach}
JJ> Now here's the weird part .. all of the input/hidden fields show up,
JJ> but not the assigned variables. The last one drops off and isn't
JJ> available.
JJ> if I add in another:
JJ> {assign var="order_$key" value="$item"}
JJ> after the input, it works.
JJ> Martin Kjeldsen seem to have a similar problem:
JJ>
http://marc.theaimsgroup.com/?l=smarty-general&m=101786148311641&w=2
JJ> but there was no resolution there...
JJ> any ideas?
JJ> --
JJ> Best regards,
JJ> guido mailto:sguido@rogers.com
JJ> --
JJ> Smarty General Mailing List (http://smarty.php.net/)
JJ> To unsubscribe, visit: http://www.php.net/unsub.php
--
Best regards,
guido mailto:sguido@rogers.com