views:

150

answers:

2

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?

+1  A: 
{php}
    echo $xml->{'video-player'};
{/php}
Ivo Sabev
Makes sense, but I wonder if there's a way to do it without resorting to falling back to PHP...
abeger
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
A: 

In Dwoo I'll try with

{$xml->`video-player`}

maybe in Smarty it will work too.

hsz
No dice, sadly.
abeger