Re: Need advice / suggestions
| From: | Ivo Jansch | Date: | Wed, 28 Mar 2001 12:33:11 +0000 |
| Subject: | Re: Need advice / suggestions | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-473@lists.php.net to get a copy of this message | ||
Hi,
Alain Fontaine wrote:
> <Book>
> <Author>Alain</Author>
> <Author>Monte</Author>
> </Book>
You could make your top-level xml thingee an array. So if your toplevel
is 'book', I'd make an array of books, with associative arrays of all
the subelements.
So in this case:
$smarty->assign("books", array( // the array of books
array( // associative array
// with the info about one book
"title"=>"Smarty for Dummies",
"author"=>Array("Alain","Monte"),
"isbn"=>"23452",
"etc"=>"other stuff")));
and then your template would look something like this:
<body>
All my books:
{section name=sec1 loop=$books}
{include file=book.tpl book=$sec1/books} // a separate file for the
book template
or // inline template
<br>{$sec1/books.title}
<br>Authors:<ul>
{section name=authors loop=$sec1/books.author}
<li>$sec1/books.author
{/section}
</ul>
{/section}
</body>
BUT, then you run into the same problem I had this morning (see my
previous posts), which makes me kinda happy because I'm not the only one
for which a solution would be handy.
Another possibility is using a lot of assigns:
$smarty->assign("booktitles"=>array("Smarty for dummies",
"The ultimate guide to Smarty");
$smarty->assign("bookauthors"=>array(array("Alain","Monty"),
array("Andrei","Monty"));
But this is less intuitive (the other method keeps your 'xml-hierarchy'
sort of intact), and requires more from the piece of code that converts
xml to the assigns.
--
Ivo Jansch <ivo@ibuildings.nl>
ibuildings.nl BV - information technology
http://www.ibuildings.nl