1

I've got a PHP page that parses an XML file with SimpleXml, then passes that object to a Smarty template. My problem is that the XML file has hyphens in its tag names, e.g. video-player. In PHP, this is no problem, I just use $xml->{'video-player'} and everything's fine. Smarty, on the other hand, throws a fit when I try to use that syntax.

The only solution I've come up with so far is to use a variable to store the name, e.g.,

{ assign var=name value="video-player" }
{ $xml->$name }

But this isn't terribly graceful to say the least. Is there another, better, approach to referring to a hyphenated variable name in Smarty?

abeger
  • 6,766
  • 7
  • 41
  • 58

3 Answers3

3
{php}
    echo $xml->{'video-player'};
{/php}
Ivo Sabev
  • 5,230
  • 1
  • 26
  • 38
  • Makes sense, but I wonder if there's a way to do it without resorting to falling back to PHP... – abeger Apr 08 '10 at 18:15
  • The other way is to change the Smarty delimiters { and } with something different, but it will be easier just to do the {php} thing - http://www.smarty.net/manual/en/language.escaping.php – Ivo Sabev Apr 08 '10 at 18:25
0

In Dwoo I'll try with

{$xml->`video-player`}

maybe in Smarty it will work too.

hsz
  • 148,279
  • 62
  • 259
  • 315
0

You just need to put it inside single quotes.

It also works on comparission blocks like:

{if $variable == 'hyphenated-value'} it works! {/if}

instead of

{if $variable == hyphenated-value} do not work! {/if}
Ken Rosaka
  • 599
  • 1
  • 5
  • 5