|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
clj83 Smarty Regular
Joined: 16 Oct 2009 Posts: 44
|
Posted: Sun May 12, 2013 8:42 am Post subject: Unexpected "@", How to avoid? |
|
|
I am using an XML feed which unfortunately uses the @ symbol within some of the definitions. Here is an example,
Code: |
SimpleXMLElement Object
(
[@attributes] => Array
(
[Name] => Cirrus Blue Demo
[Status] => 0
[Latitude] => 0.0
[Longitude] => 0.0
[Units] => Metric
)
[Sensor] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Name] => Internal Temperature Sensor
[Port] => 1
[Status] => 0
)
|
Theoretically I should be able to print the name of the sensor using,
Code: | {$xmlMod->Sensor[0]->@attributes->Name} |
However, it does not work because the @ symbol breaks the Smarty Compiler.
Syntax Error in template "module_db_tpl:XMLMadeSimple;sensorsLive" on line 11 "{$xmlMod->Sensor[0]->Condition->@attributes->Type}" - Unexpected "@", expected one of: "{" , "$" , "identifier"
Does anyone know how to resolve this?
Thanks |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun May 12, 2013 2:16 pm Post subject: |
|
|
try this:
{assign var=attr value="{@attributes}"}
{$xmlMod->Sensor[0]->$attr->Name}
I'm not sure if Smarty 3 supports in-line syntax, you might also try:
{$xmlMod->Sensor[0]->{@attributes}->Name} |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun May 12, 2013 8:36 pm Post subject: |
|
|
It must be
Code: | {assign var=attr value="@attributes"}
{$xmlMod->Sensor[0]->$attr->Name} |
There is no working inline syntax: |
|
Back to top |
|
clj83 Smarty Regular
Joined: 16 Oct 2009 Posts: 44
|
Posted: Thu May 16, 2013 6:26 pm Post subject: |
|
|
Thanks for your suggestions. I have tried all sorts of combinations and nothing seems to work, any other ideas of an approach I could try? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu May 16, 2013 8:54 pm Post subject: |
|
|
ay be it should be
Code: | {assign var=attr value="@attributes"}
{$xmlMod->Sensor[0]->$attr['Name']} |
as 'Name' is an array index and not an object property |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|