Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

assign var to var

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
RGordijn
Smarty Rookie


Joined: 21 Jan 2008
Posts: 15

PostPosted: Fri May 09, 2008 6:19 pm    Post subject: assign var to var Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri May 09, 2008 7:39 pm    Post subject: Reply with quote

The standard SMARTY syntax does not allow this. But I have written a modifier varvar which does solve the problem.

Your will find it in the middle of this thread http://www.phpinsider.com/smarty-forum/viewtopic.php?t=12678&start=0

Code:
{"value_$k"|varvar}  will return the right result.
Back to top
View user's profile Send private message
RGordijn
Smarty Rookie


Joined: 21 Jan 2008
Posts: 15

PostPosted: Sun May 11, 2008 12:33 pm    Post subject: Reply with quote

u.tews,

it looks great, but i just doesn't work Razz

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun May 11, 2008 1:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
RGordijn
Smarty Rookie


Joined: 21 Jan 2008
Posts: 15

PostPosted: Sun May 11, 2008 1:07 pm    Post subject: Reply with quote

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 Razz
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun May 11, 2008 1:16 pm    Post subject: Reply with quote

Just another question: Caching is disabled?

Did you check with {debug} if there is a variable value_nl and value_en?
Back to top
View user's profile Send private message
RGordijn
Smarty Rookie


Joined: 21 Jan 2008
Posts: 15

PostPosted: Sun May 11, 2008 1:31 pm    Post subject: Reply with quote

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.. Smile )

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun May 11, 2008 1:36 pm    Post subject: Reply with quote

Caching must stay off. As i said the {foreach} is working here.
Back to top
View user's profile Send private message
RGordijn
Smarty Rookie


Joined: 21 Jan 2008
Posts: 15

PostPosted: Mon May 12, 2008 10:39 am    Post subject: Reply with quote

foreach is working o.k.
but i still didn't get it to work properly.

but! i got a solution that also works Smile

<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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP