Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: [SMARTY] Referencing complex associative array
It is a bit hard to read the structure...but i think...


$result->ITEMS is the array with your news items
so

{section name=3Dnews loop=3D$result.ITEMS}
<tr>
<td>
{$result.ITEMS.[news].LINK}
</td>
</tr>
{/section}

But I am a bit  from your email what is $result and what is $news.

Abdul-Wahid

This would would loop through the news items.
On 4/28/05, Roger Thomas <sniper@home.net.my> wrote:
> Hi,
> I parsed an XML file and pushed the results into an array. My question is=
, when I assign this array, $result,  to Smarty, how do I reference it ?
>=20
> I have something like:
>   {section name=3Dfeed loop=3D$news}
>   <tr>
>     <td>
>       {$news[feed].COPYRIGHT}
>     </td>
>   </tr>
>   {/section}
>=20
> How do I reference, say, the LINK under ITEMS ? Please advise.
>=20
> If I do a var_dump on $result, it looks like this:
>=20
> array(10) {
>   ["TITLE"]=3D>
>   string(39) "BBC News | News Front Page | UK Edition"
>   ["LINK"]=3D>
>   string(47) "http://news.bbc.co.uk/go/rss/-/1/hi/default.stm"
>   ["DESCRIPTION"]=3D>
>   string(33) "Updated every minute of every day"
>   ["LANGUAGE"]=3D>
>   string(5) "en-gb"
>   ["LASTBUILDDATE"]=3D>
>   string(27) "Wed, 27 Apr 05 23:59:27 GMT"
>   ["COPYRIGHT"]=3D>
>   string(92) "Copyright: (C) British Broadcasting Corporation, http://new=
s.bbc.co.uk/1/hi/help/3281849.stm"
>   ["DOCS"]=3D>
>   string(33) "http://www.bbc.co.uk/syndication/"
>   ["TTL"]=3D>
>   string(2) "15"
>   ["IMAGE"]=3D>
>   array(3) {
>     ["TITLE"]=3D>
>     string(8) "BBC News"
>     ["URL"]=3D>
>     string(56) "http://news.bbc.co.uk/nol/shared/img/bbc_news_120x60.gif"
>     ["LINK"]=3D>
>     string(21) "http://news.bbc.co.uk"
>   }
>   ["ITEMS"]=3D>
>   array(5) {
>     [0]=3D>
>     array(5) {
>       ["TITLE"]=3D>
>       string(31) "Early Iraq legal opinion leaked"
>       ["DESCRIPTION"]=3D>
>       string(115) "The attorney general doubted the Iraq war would be leg=
al without a new resolution from the UN, leaked advice shows."
>       ["LINK"]=3D>
>       string(79) "http://news.bbc.co.uk/go/rss/-/1/hi/uk_politics/vote_20=
05/frontpage/4491105.stm"
>       ["GUID"]=3D>
>       string(70) "http://news.bbc.co.uk/1/hi/uk_politics/vote_2005/frontp=
age/4491105.stm"
>       ["PUBDATE"]=3D>
>       string(27) "Wed, 27 Apr 05 22:32:09 GMT"
>     }
>     [1]=3D>
>     array(5) {
>       ["TITLE"]=3D>
>       string(32) "Man arrested over Abigail attack"
>       ["DESCRIPTION"]=3D>
>       string(96) "A 25-year-old man has been arrested by detectives hunti=
ng the man who stabbed Abigail Witchalls."
>       ["LINK"]=3D>
>       string(73) "http://news.bbc.co.uk/go/rss/-/1/hi/england/southern_co=
unties/4492119.stm"
>       ["GUID"]=3D>
>       string(64) "http://news.bbc.co.uk/1/hi/england/southern_counties/44=
92119.stm"
>       ["PUBDATE"]=3D>
>       string(27) "Wed, 27 Apr 05 23:53:19 GMT"
>     }
>     [2]=3D>
>     array(5) {
>       ["TITLE"]=3D>
>       string(32) "Jackson's ex-wife in witness box"
>       ["DESCRIPTION"]=3D>
>       string(122) "Prosecutors in Michael Jackson's child abuse trial beg=
in questioning the star's ex-wife and mother of two of his children."
>       ["LINK"]=3D>
>       string(67) "http://news.bbc.co.uk/go/rss/-/1/hi/entertainment/music=
/4490259.stm"
>       ["GUID"]=3D>
>       string(58) "http://news.bbc.co.uk/1/hi/entertainment/music/4490259.=
stm"
>       ["PUBDATE"]=3D>
>       string(27) "Wed, 27 Apr 05 21:58:53 GMT"
>     }
>     [3]=3D>
>     array(5) {
>       ["TITLE"]=3D>
>       string(33) "US terror charge Briton convicted"
>       ["DESCRIPTION"]=3D>
>       string(112) "A British man is found guilty of attempting to support=
terrorism after trying to sell a missile to an FBI agent."
>       ["LINK"]=3D>
>       string(50) "http://news.bbc.co.uk/go/rss/-/1/hi/uk/4491181.stm"
>       ["GUID"]=3D>
>       string(41) "http://news.bbc.co.uk/1/hi/uk/4491181.stm"
>       ["PUBDATE"]=3D>
>       string(27) "Wed, 27 Apr 05 20:07:48 GMT"
>     }
>     [4]=3D>
>     array(5) {
>       ["TITLE"]=3D>
>       string(28) "Airbus A380 completes flight"
>       ["DESCRIPTION"]=3D>
>       string(103) "The world's largest passenger plane, the Airbus A380, =
lands safely, having completed its maiden flight."
>       ["LINK"]=3D>
>       string(56) "http://news.bbc.co.uk/go/rss/-/1/hi/business/4488361.st=
m"
>       ["GUID"]=3D>
>       string(47) "http://news.bbc.co.uk/1/hi/business/4488361.stm"
>       ["PUBDATE"]=3D>
>       string(27) "Wed, 27 Apr 05 17:32:10 GMT"
>     }
>   }
> }
>=20
> --
> Roger
>=20
> ---------------------------------------------------
> Sign Up for free Email at http://ureg.home.net.my/
> ---------------------------------------------------
>=20
> --
> Smarty General Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>=20
>

Report this thread to moderator Post Follow-up to this message
Old Post
Abdul-Wahid Paterson
04-28-05 01:58 PM


Re: [SMARTY] Referencing complex associative array
Abdul-Wahid Paterson wrote:
> {section name=news loop=$result.ITEMS}
>      ...{$result.ITEMS.[news].LINK}...
> {/section}

Roger Thomas wrote:
How do I reference, say, the LINK under ITEMS ? Please advise.
 
... 
...

For complex array structures I find it easier to read/write the template
markup by using assign() here, especially if you're going to use
multiple values from the array:

<ul>
{section name=news value=$result.ITEMS}
{assign value=$result.ITEMS[news] var="item"}
<li>
<h3><a href="{$item.LINK}">{$item.TITLE}</a></h3>
<p>{$item.DESCRIPTION}</p>
</li>
{/section}
</ul>

FWIW!
--
Maximillian Von Schwanekamp
http://www.neptunewebworks.com/

Report this thread to moderator Post Follow-up to this message
Old Post
Maximillian Schwanekamp
04-29-05 02:01 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Smarty Templates archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:21 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.