View previous topic :: View next topic |
Author |
Message |
RGordijn Smarty Rookie
Joined: 21 Jan 2008 Posts: 15
|
Posted: Fri May 09, 2008 6:19 pm Post subject: assign var to var |
|
|
Hi!
Lets say I got an php-array:
$lang['nl'] = 'dutch';
$lang['en'] = 'english';
.. etc .. you get the picture..
next thing is looping through those values:
{foreach from=$lang.languages key=k item=v}
language: {$v} <input type="text" name="value_{$k}" value="{$value_$k}">
{/foreach}
getting this result:
<input type="text" name="value_nl" value="{$value_nl}">
<input type="text" name="value_eng" value="{$value_en}">
cause {$value_nl} and {$value_en} wil hold some content... any ideas howto make a var like {$value_[nl|eng]} ?
thanks! |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
RGordijn Smarty Rookie
Joined: 21 Jan 2008 Posts: 15
|
Posted: Sun May 11, 2008 12:33 pm Post subject: |
|
|
u.tews,
it looks great, but i just doesn't work
if I post my form, the value's of it are automaticly assign into smarty again.
I checked the values in the debug console, so no doubt that the values are actually there.
but it just wont return the value...
the modifier receives the $string correct, but somehow when return it cant find that value in the tpl-vars array...
assign the value_nl/en in tpl or php also wont do the job.
weird :S |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun May 11, 2008 1:04 pm Post subject: |
|
|
If you have
$lang['nl'] = 'dutch';
$lang['en'] = 'english';
as array your {foreach} loop is wrong.
Code: |
{foreach from=$lang key=k item=v}
language: {$v} <input type="text" name="value_{$k}" value="{"value_$k"|varvar}">
{/foreach}
|
This does work at my place |
|
Back to top |
|
RGordijn Smarty Rookie
Joined: 21 Jan 2008 Posts: 15
|
Posted: Sun May 11, 2008 1:07 pm Post subject: |
|
|
haha thats true.
I made a mistake, $lang is just a HUGE array with alle the 'language', en i got:
$lang['languages']['nl'] = 'dutch';
$lang['languages']['en'] = 'english';
So my foreach works perfect. it's just that I cant get to the darn value |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun May 11, 2008 1:16 pm Post subject: |
|
|
Just another question: Caching is disabled?
Did you check with {debug} if there is a variable value_nl and value_en? |
|
Back to top |
|
RGordijn Smarty Rookie
Joined: 21 Jan 2008 Posts: 15
|
Posted: Sun May 11, 2008 1:31 pm Post subject: |
|
|
caching, nope. i didn't create the directory and didn;t told smarty to use it.
( while I'm typing this, I thinkin' about turning it on.. )
and debug, yes. I qoute:
Quote: | I checked the values in the debug console, so no doubt that the values are actually there. |
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun May 11, 2008 1:36 pm Post subject: |
|
|
Caching must stay off. As i said the {foreach} is working here. |
|
Back to top |
|
RGordijn Smarty Rookie
Joined: 21 Jan 2008 Posts: 15
|
Posted: Mon May 12, 2008 10:39 am Post subject: |
|
|
foreach is working o.k.
but i still didn't get it to work properly.
but! i got a solution that also works
<input type="text" name="value[{$k}]" value="{$value[$k]}">
just make a html array with value[] and $k, and I'm done!
lol, to easy, thanks anyway! |
|
Back to top |
|
|