How do I access variables with hyphenated names in Smarty?
Posted
by abeger
on Stack Overflow
See other posts from Stack Overflow
or by abeger
Published on 2010-04-08T17:11:10Z
Indexed on
2010/04/08
17:23 UTC
Read the original article
Hit count: 382
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?
© Stack Overflow or respective owner