RE: Including a template into a template more than once.

From: Date: Sat, 27 Sep 2003 14:15:47 +0000
Subject: RE: Including a template into a template more than once.
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10278@lists.php.net to get a copy of this message
Hi, I actually posted the solution in a post nearly at the same time. http://news.php.net/article.php?group=php.smarty.general&article=10274 You can assign variables directly in the {include file="menu.tpl"} statement. Like this: {include file="menu.tpl" menu_items=$menu_item.sub_menus} Martin Kjeldsen > -----Original Message----- > From: Webmaster [mailto:webmaster@dentona.de] > Sent: 26. september 2003 14:12 > To: smarty-general@lists.php.net > Subject: Including a template into a template more than once. > > > 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 >

« previous php.smarty.general (#10278) next »