Hallo André,
Wie kann man Schleifen bei Smarty einsetzen?
{section loop=$Array name=namederschleife}
...
{/section}
Und wenn ich schon einmal was schreibe, wie kann ich Templates verschachteln?
Was verstehst Du unter verschachteln?
// index.tpl
-------------------------------------------------------
{include file="kopf.tpl"}
{section loop=$MeineZeilen name=tabellenschleife}
<tr><td>{$MeineZeilen[tabellenschleife]}</td></tr>
{/section}
{include file="fuss.tpl"}
(body.tpl und zeile.tpl brauchst Du nicht mehr, Du kannst sie natürlich noch definieren, allerdings ist das komplizierter als so)
Variante 1:
require 'Smarty.class.php';
$smarty = new Smarty;
$smarty->caching = false;
$smarty->compile_check = true;
$smarty->debugging = false;
$meinArray = array ();
for($i=0;$i<10;$i++)
{
$meinArray[] = $i;
}
$smarty->assign ('MeineZeilen', $meinArray);
$smarty->display('index.tpl');
Variante 2:
require 'Smarty.class.php';
$smarty = new Smarty;
$smarty->caching = false;
$smarty->compile_check = true;
$smarty->debugging = false;
for($i=0;$i<10;$i++)
{
$smarty->append ('MeineZeilen', $i);
}
$smarty->display('index.tpl');
Viele Grüße,
Christian
| http://www.selflinux.org/ |
| http://aktuell.de.selfhtml.org/tippstricks/beitrag.htm |
| sh:) fo:) ch:] rl:( br:> n4:& ie:% mo:) va:) de:] zu:) fl:( js:| ss:) ls:[ |
| http://emmanuel.dammerer.at/selfcode.html |