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

Variable in Variable

 
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 -> Language: German
View previous topic :: View next topic  
Author Message
nerd
Smarty n00b


Joined: 11 Sep 2013
Posts: 2

PostPosted: Wed Sep 11, 2013 11:19 am    Post subject: Variable in Variable Reply with quote

Hallo Zusammen,
ich weiß das es in Smarty 2 nicht geht. Aber ich brauche es irgendwie Embarassed

Wofür:
Code:

[{foreach from=$iso_lang item=iso_lang_values}]
[{$edit->tabellenname__tabellenspalte_[{$iso_lang_values->id}]->value}]
[{/foreach}]


Ich brauche im Prinzip (je nach Arrayelement):
Code:
[{$edit->tabellenname__tabellenfeld_2->value}] oder
[{$edit->tabellenname__tabellenfeld_10->value}] als Rückgabe


Ich habe das ganze auch schon mit PHP hinbekommen. Aber dann wird [{$edit->tabellenname__tabellenfeld_10->value}] nicht als Variable erkannt sondern als String ausgegeben.

Hier mein PHP Versuch:
Code:
[{foreach from=$iso_lang item=iso_lang_values}]
[{php}]
$varname = "[{\$edit->tabellenname__tabellenfeld_".$this->get_template_vars('valueindex')."->value}]";
$this->assign('value', $varname);
[{/php}]
[{$varname}]
[{/foreach}]


Als Ergebnis bekomme ich wie oben schon erwähnt folgendes leider nur als String [{$edit->tabellenname__tabellenfeld_10->value}] und nicht als Variable die auf das Tabellenfeld zu greift. Sprich es müsste test ausgegeben werden.

Ich kann an der Datenbankabfrage und an dem Array leider nichts ändern.

Hat jemand von euch noch eine Idee wie ich das hinbekommen kann Question Question Question Question Question Question

Kann man den String vielleicht als Variable konvertieren oder kann man direkt die verschachtelte Variable nutzbar machen? Gibt es vielleicht ein Smarty plugin dazu oder gibt es vielleicht einen ganz anderen Lösungs weg?
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Wed Sep 11, 2013 2:17 pm    Post subject: Reply with quote

Mit Smarty 2 hast Du gleich 2 Probleme.
1. Variable Variablennamen (dafür Hilfsvariable $foo) sind nicht möglich
2. Object chaining wird nicht unterstützt (dafür Hilfsvariable $bar)

Folgendes sollte gehen
Code:
[{foreach from=$iso_lang item=iso_lang_values}]
[{assign var='foo' value="tabellenname__tabellenspalte_`$iso_lang_values->id`"}]
[{assign var='bar' value=$edit->$foo}]
[{$bar->value}]
[{/foreach}]
Back to top
View user's profile Send private message
nerd
Smarty n00b


Joined: 11 Sep 2013
Posts: 2

PostPosted: Thu Sep 12, 2013 8:06 am    Post subject: Reply with quote

Hallo U.Tews,

Leider liefert mir deine Variante nur null zurück.

Dein Code mit Dumps:
Code:
[{foreach from=$iso_lang item=iso_lang_values}]
[{assign var='foo' value="tabellenname__tabellenspalte_`$iso_lang_values->id`"}]
[{$foo|@var_dump}]
[{assign var='bar' value=$edit->$foo}]
[{$bar|@var_dump}]
[{$bar->value}]
[{$bar|@var_dump}]
[{/foreach}]


Rückgabe:
string 'tabellenname__tabellenspalte_0' (length=30)
null
null
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Fri Sep 13, 2013 8:33 pm    Post subject: Reply with quote

Hmm


was liefert Dir denn ein var_dump von $edit?
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 -> Language: German 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