Re: [SMARTY] dynamically creating variable names
| From: | messju mohr | Date: | Fri, 07 Mar 2003 20:13:45 +0000 |
| Subject: | Re: [SMARTY] dynamically creating variable names | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8483@lists.php.net to get a copy of this message | ||
On Fri, Mar 07, 2003 at 08:33:23PM +0100, Ronny 'Ronino' Multrus wrote:
> Hello,
>
> I recently read about the Smarty Template Engine, tested it and was amazed:
> It's wonderful!
>
> Okay, now I came across a problem: I'm looking for a way of dynamically
> creating variable names. In an html-form I have different sections, so I give
> the input names different prefixes, according to the respective section:
> name="{$varPrefix}_example" will become something like
> name="prefix_example".
> Now the problem is that I can't access the according variable in smarty's
> post-array. I've read that in the latest release 2.5RC1 something like
> $smarty.post.$varName is possible, but what I need is something like
> $smarty.post.[$varPrefix . "_example"].
this it not possible in one stroke AFAIK
> Do you have any suggestions how to do that? Or how could I create $varName
> before accessing the post-array to have something like
> $smarty.post.$varWithPrefix?
{assign var=varWithPrefix value="$
varPrefix_example"}
{$smarty.post.$varWithPrefix}
but you may want to to something like this in php, before $smarty->display()
(not tested, but the principle should get clear)
$vars = array();
foreach ($_POST as $name=>$value) {
if (substr($name, 0, strlen($prefix))==$prefix)
$vars[substr($name, strlen($prefix))] = $value;
}
$smarty->assign('vars', $vars);
then you have an easy life in your template, using $vars.$name and the
like.
have fun
messju
> Thanx in advance
> Ronino
>
>
>
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
Torx-Schrauben: Hände-Weg-Schrauben
nach Marc Habers Kollegen