|
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 |
Palumba Smarty n00b
Joined: 06 Feb 2015 Posts: 3
|
Posted: Fri Feb 06, 2015 2:29 pm Post subject: smarty simplexml show elements with IDs |
|
|
I have an XML-Feed with the following structure:
<id>12</id>
<author>asasasa</author>
<date>2013-01-31 12:20:48</date>
<reviewerAge>80</reviewerAge>
<subcategoryRatings>
<subcategoryRating>
<category id="price">Rates</category>
<rating scale="5">4</rating>
<comment/>
</subcategoryRating>
<subcategoryRating>
<category id="room">Rooms</category>
<rating scale="5">4</rating>
<comment/>
</subcategoryRating>
<subcategoryRating>
<category id="location">Location</category>
<rating scale="5">3</rating>
<comment/>
</subcategoryRating>
<subcategoryRating>
<category id="service">Service</category>
<rating scale="5">5</rating>
<comment/>
</subcategoryRating>
</subcategoryRatings>
With the following simplexml I'm able to display the "id","author" and "date" elements, but not the "category" and "rating" elements.
{$xml = simplexml_load_file('xml.file')}
{foreach from=$xml item=list name='outer' }
{foreach from=$list item=ex name='loop' }
{if !$smarty.foreach.outer.first}
<h1> [{$smarty.foreach.loop.iteration}] </h1>
{$ex->author}<br />
{$ex->id}<br />
{$ex->date}<br />
{/if}
{/foreach}
{/foreach}
How can I do this?
Thank you very much.
Greetings |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Feb 06, 2015 6:29 pm Post subject: |
|
|
That's because they aren't in the scope of your loops.
Your structure actually looks like this:
Code: | <element>
<id>12</id>
<author>asasasa</author>
<date>2013-01-31 12:20:48</date>
<reviewerAge>80</reviewerAge>
<subcategoryRatings>
<subcategoryRating>
<category id="price">Rates</category>
<rating scale="5">4</rating>
<comment/>
</subcategoryRating>
<subcategoryRating>
<category id="room">Rooms</category>
<rating scale="5">4</rating>
<comment/>
</subcategoryRating>
<subcategoryRating>
<category id="location">Location</category>
<rating scale="5">3</rating>
<comment/>
</subcategoryRating>
<subcategoryRating>
<category id="service">Service</category>
<rating scale="5">5</rating>
<comment/>
</subcategoryRating>
</subcategoryRatings>
</element> |
To access "category", you need a few more loops in there.
Also, you're using deprecated foreach syntax. |
|
Back to top |
|
Palumba Smarty n00b
Joined: 06 Feb 2015 Posts: 3
|
Posted: Fri Feb 06, 2015 6:51 pm Post subject: |
|
|
Hi Deamon,
thank you for your answer.
How can I do this?
Can you give me an example?
Greetings |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
Palumba Smarty n00b
Joined: 06 Feb 2015 Posts: 3
|
Posted: Sat Feb 07, 2015 2:23 pm Post subject: |
|
|
Got it with:
{$ex->subcategoryRatings->subcategoryRating[0]->category} |
|
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
|