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

Hyphen in array key

 
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 -> General
View previous topic :: View next topic  
Author Message
bpmccain
Smarty n00b


Joined: 17 Feb 2012
Posts: 2

PostPosted: Fri Feb 17, 2012 1:50 pm    Post subject: Hyphen in array key Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Feb 17, 2012 2:52 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
bpmccain
Smarty n00b


Joined: 17 Feb 2012
Posts: 2

PostPosted: Fri Feb 17, 2012 4:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Fri Feb 17, 2012 4:56 pm    Post subject: Reply with quote

Or use
Code:
{$form['phone-1-1']['label']}
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 -> General 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