Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smarty Variable - Hyphen in Array Key

Tags:

smarty

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:

  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:

{$form.phone-1-1.label}

fails because of the hyphens.

Any ideas how I get around that?

like image 961
bpmccain Avatar asked Sep 05 '25 23:09

bpmccain


1 Answers

The only workaround you can use is:

{assign var="mykey" value="phone-1-1"}
{$form.$mykey.label}

The bult-in Smarty function {assign} let you create variables directly in the template.

http://www.smarty.net/docs/en/language.function.assign.tpl (for Smarty 3)
http://www.smarty.net/docsv2/en/language.custom.functions.tpl (for Smarty 2)

like image 171
lorenzo-s Avatar answered Sep 11 '25 01:09

lorenzo-s