|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bpmccain Smarty n00b
Joined: 17 Feb 2012 Posts: 2
|
Posted: Fri Feb 17, 2012 1:50 pm Post subject: Hyphen in array key |
|
|
Trying to display a Smarty variable with a hyphen in the key. Nothing I can do to change the fact that it has a hyphen in the key.
For example, a phone number may be stored within the $form array as:
Code: | phone-1-1 => Array (9)
name => "phone-1-1"
value => "(555) 555-5555"
type => "text"
frozen => false
required => false
error => null
id => "phone-1-1"
label => "<label for="phone-1-1">Phone Number (..."
html => "<input maxlength="32" size="20" name=..." |
Trying to print the smarty variable using:
Code: | {$form.phone-1-1.label} |
fails because of the hyphens.
Any ideas how I get around that? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Feb 17, 2012 2:52 pm Post subject: |
|
|
one work around:
{$foo = "phone-1-1"}
{$form.$foo.label}
Hyphens in keys are trouble, same as in PHP. Try to avoid them. |
|
Back to top |
|
bpmccain Smarty n00b
Joined: 17 Feb 2012 Posts: 2
|
Posted: Fri Feb 17, 2012 4:46 pm Post subject: |
|
|
Thanks, that works.
As I said, I unfortunately can't avoid them as they are coming from a system that I am not in control of. Not ideal but at least I now have a solution. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Feb 17, 2012 4:56 pm Post subject: |
|
|
Or use
Code: | {$form['phone-1-1']['label']} |
|
|
Back to top |
|
|
|
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
|