Including a template into a template more than once.
| From: | Webmaster | Date: | Fri, 26 Sep 2003 12:11:56 +0000 |
| Subject: | Including a template into a template more than once. | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-10273@lists.php.net to get a copy of this message | ||
Hi,
I already posted 2 days ago and Messju was kind enought to give me some
hints.
I followed his suggestions and I just don't get it. The problem is as
follows:
The page news.php has the following function:
function initMenu()
{
$menu = array();
$this->oGipsMenu = new Menutable_Gipse($this->aTrans['gipse'],
$this->aTrans);
$this->oModelMenu = new Menutable($this->aTrans['modelherstellung'],
$this->aTrans);
$this->oEinbettMenu = new Menutable($this->aTrans['einbettmassen'],
$this->aTrans);
$this->oLabMenu = new Menutable($this->aTrans['laborhilfsmittel'],
$this->aTrans);
// Here the arrays for the menu entries wich be put into another array
called $menu
// the arrays look like this:
// $this->menuItems[0]['id'] = "2110";
// $this->menuItems[0]['trans'] = $aTrans['gipsgebundeneEinbettmassen'];
// $this->menuItems[1]['id'] = "2120";
// $this->menuItems[1]['trans'] =
$aTrans['phosphatgebundeneEinbettmassen'];
...
...
array_push($menu, $this->oGipsMenu->menuItems,
$this->oLabMenu->menuItems,
$this->oModelMenu->menuItems,
$this->oEinbettMenu->menuItems,
$this->oLabMenu->menuItems);
$this->assignVars("menu", $menuItems);
$this->assignVars('menuSpecs', $menuSpecs);
}
The function assignVars looks like this:
function assignVars($varname, $value)
{
// if varname is not passed assign keys and values
if (($varname == "") & (isset($value)))
{
while (list($key, $val) = each($value))
{
$this->smarty->assign($key, $val);
}
}
elseif (isset($varname) & isset($value))
{
$this->smarty->assign($varname, $value);
}
}
The template "news.tpl" is supposed to include the "menu.tpl" (menu.tpl is
simply a a table with the menu entries as links to the different pages)
Here is what I don't understand:
How can I include that "menu.tpl" severtal times and use different values
each time?
So for each included table I would like to use the values of the arrays,
$einbettmassen,$gipse, etc accordingly.
I was told to use {foreach} which I don't quite understand:
<td width="25%" valign="top" align="left">
{foreach from=$menuItems item=menu}
{include file="menu.tpl"} <br />
{/foreach}
</td>
???
Thank you very much.
Webmaster