Re: nested template question
| From: | Maciek Uhlig | Date: | Tue, 27 Mar 2001 10:33:02 +0000 |
| Subject: | Re: nested template question | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-446@lists.php.net to get a copy of this message | ||
OK, here is the working example (at least for me, hope it'll work for you
:-)):
index.php:
<?php
require("Smarty.class.php");
$smarty = new Smarty;
$smarty->assign("mybookmarks",
array(array("url" => "http://www.achievo.com", "name" =>
"Achievo"),
array("url" => "http://www.google.com", "name" =>
"Google")));
$smarty->assign("yourbookmarks",
array(array("url" => "http://www.ibuildings.nl", "name" =>
"Ibuildings"),
array("url" => "http://www.altavista.com", "name" =>
"Altavista")));
$smarty->display('indexitem.tpl');
?>
indexitem.tpl:
My bookmarks:
{section name=mysection loop=$mybookmarks}
{include file="item.tpl" table=$mybookmarks}
{/section}
<br><br>Your bookmarks:
{section name=mysection loop=$yourbookmarks}
{include file="item.tpl" table=$yourbookmarks}
{/section}
item.tpl:
<a href="{$mysection/table.url}">{$mysection/table.name}</a>
HTML output:
<!-- Smarty 1.3.1pl1 2001-03-27 12:31:36 -->
My bookmarks:
<a href="http://www.achievo.com">Achievo</a> <a
href="http://www.google.com">Google</a><br><br>Your
bookmarks:
<a href="http://www.ibuildings.nl">Ibuildings</a>
<a
href="http://www.altavista.com">Altavista</a>
Watch how:
- associative arrays are used in item.tpl (key and value are separated with
a period)
- table variable is passed to item.tpl
- section name is reused ("mysection")
- item.tpl is reused as you requested.
Maciek