4

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?

0

1 Answer 1

4

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)

Sign up to request clarification or add additional context in comments.

1 Comment

You can also do {$form["phone-1-1"].label} as well which is slightly cleaner then doing {assign}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.