Variable variables revisited

From: Date: Tue, 25 Mar 2003 14:23:57 +0000
Subject: Variable variables revisited
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8887@lists.php.net to get a copy of this message
Having see the other guys' troubles with variable variables, it reminded me of a problem I had to work round a few weeks back, and I'd like it addressed, so here it is. phpBugTracker has a language file called "en.php" for English text containing a few associative arrays ($STRING, $TITLE, etc) for form contents. I was trying to access these arrays using a variable key from within Smarty templates like so: Title: {$STRING.$title} where $title is a variable containing the key name of a value I want to use. Of course, this doesn't work, and nor do several kludged attempts like: {assign var=$x value='$STRING.'+$title} // no good Title: {$$x} So I ended up assigning a variable for it from the PHP code: $t->assign('title',$STRING[$title]); where $t is the Smarty template object, and then Title: {$title} in the template itself. I'm sure this isn't something that can be done differently, but if anyone knows different.....! Garp

« previous php.smarty.general (#8887) next »