Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Unexpected "@", How to avoid?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
clj83
Smarty Regular


Joined: 16 Oct 2009
Posts: 44

PostPosted: Sun May 12, 2013 8:42 am    Post subject: Unexpected "@", How to avoid? Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Sun May 12, 2013 2:16 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun May 12, 2013 8:36 pm    Post subject: Reply with quote

It must be

Code:
{assign var=attr value="@attributes"}
{$xmlMod->Sensor[0]->$attr->Name}


There is no working inline syntax:
Back to top
View user's profile Send private message
clj83
Smarty Regular


Joined: 16 Oct 2009
Posts: 44

PostPosted: Thu May 16, 2013 6:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu May 16, 2013 8:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP