You are here: Re: [SMARTY] Dynamic Variables « Smarty Templates Posts « IT news, forums, messages
Re: [SMARTY] Dynamic Variables

Posted by Monte Ohrt on 06/01/05 16:20

You can get around this with a temporary assign:

{assign var="pagekey" value="page_key_`$DIGIT`_value"}
{$page_obj->$pagekey}


But why not make easier... instead of:

$type_varname = 'page_key_' . $digit. '_type';
$this->{$type_varname} = $rs->fields['page_key_' . $digit . '_type'];

Do something like:

$this->page_key_type[$digit] = $rs->fields['page_key_' . $digit . '_type'];


Then in the template instead of creating dynamic var names, just use the
key name:

<input name="page_key_{$digit}_value"
value="{$page_obj->page_key_type.$digit}" size="10" />



Stephen J. Lawrence Jr. wrote:

> Well, I have 12 different sets of variables on this page that I
> display in a form. The html is all identical except for the variable
> names. I am trying to keep from having to hardcode 12 different HTML
> TR's for each of the vars.
>
> On the PHP side, I have done this:
> $this->digits =
> array('1','2','3','4','5','6','7','8','9','0','aa','bb','cc');
> foreach($this->digits as $digit)
> {
> $type_varname = 'page_key_' . $digit. '_type';
> $this->{$type_varname} = $rs->fields['page_key_' . $digit .
> '_type'];
> }
>
> Then I want a foreach in the template to spin through each of the
> variables.
>
> {foreach from=digits item=$digit}
> <input name="page_key_{$digit}_value"
> value="{$page_obj->page_key_$DIGIT_value}" size="10" />
> {/foreach}
>
> the "name=page_key_{$digit}_value" part works fine, but the "value="
> part does not. The first loopthrough, the value needs to be
> $page_obj->page_key_1_value, the second through needs to be
> $page_obj->page_key_2_value, etc..
>
> steve
>
> Bill Cunningham wrote:
>
>> Stephen,
>>
>> That was a much clearer explaination of what you're looking
>> for.
>>
>> It appears that perhaps you want an array there. Something
>> like:
>>
>> $my_obj->var[$cnt] ??
>>
>> What about:
>> $var = "variable_1_value";
>>
>> $my_obj->$$var ?? <<- not sure if a variable indirection
>> works in a template though.
>>
>>
>> Maybe it would help if you told us exactly why you are
>> trying to achieve this. Are you trying to auto create a
>> bunch of templates?
>>
>>
>> - Bill
>>
>>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация