|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bweichel Smarty n00b
Joined: 14 Oct 2004 Posts: 2
|
Posted: Fri Nov 19, 2004 9:13 am Post subject: Probleme mit foreach |
|
|
Hallo,
in dem Array "Groesse" habe ich mehrere Größen abgespeichert. Die Größen sind abhängig von dem jeweiligen Artikel.
Nun möchte ich, dass jeder Größenblock (die jeweiligen Größen eines Artikels) durch drei Zeilenumbrüche getrennt ausgegeben werden.
Ich habe ein Template "artikel.html" und ein Script "artikel.php" in der die Ausgabe vorbereitet wird. So wie ich es momentan gelöst habe, geht es zwar, aber wenn ich mir den Quelltext anschaue, wiederholt er das komplette Template. Das heißt, er hört nach dem ersten Größenblock bei </html> auf und fängt anschließend wieder ganz oben bei <html> im Template an. Das ist natürlich nicht richtig. Wie kann ich jeden einzelnen Größenblock ausgeben, ohne dass dabei das komplette Template neu geschrieben wird?
Hier mein Template-Script:
[php:1:2aef53aa0f]
<html>
<head>
<title>shop2be - Artikelhauptübersicht</title>
</head>
<body>
{foreach from=$groesse item=groesse}
{$groesse} <br>
{/foreach}
<br>
<br>
</body>
</html>
[/php:1:2aef53aa0f]
und jetzt mein PHP Script:
[php:1:2aef53aa0f]
<?php
include("includes/db_connect.inc.php");
include("class/class_artikel.inc.php");
define('SMARTY_DIR','smarty/');
require(SMARTY_DIR.'Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = 'templates/';
$smarty->compile_dir = 'smarty/';
$smarty->config_dir = 'smarty/configs/';
$smarty->cache_dir = 'smarty/cache/';
$artikel = new artikel;
$oberartikel = $artikel->get_oberartikel("Eins");
$smarty->assign('oberartikel', $oberartikel[oberartikel]);
$groesse = array();
foreach($oberartikel[oberartikel] as $items) {
foreach($oberartikel[unterartikel][$items[artikelnum]] as $items2) {
$groesse[] = "$items2[artikelnum]";
}
$smarty->assign('groesse', $groesse);
$smarty->display('artikel.html');
#print_r($groesse) . "<br><br>";
$groesse = "";
}
mysql_close($db);
?>
[/php:1:2aef53aa0f]
?>[/php] |
|
Back to top |
|
T. Smarty Regular
Joined: 22 Aug 2004 Posts: 69 Location: AT
|
Posted: Thu Nov 25, 2004 7:54 pm Post subject: |
|
|
Das ist ganz logisch, dass du mehrfach den html-code drin hast Du rufst ja schließlich auf öfters smarty->display(...) auf.
[php:1:ed71f6dab1]
foreach($oberartikel[oberartikel] as $items) {
foreach($oberartikel[unterartikel][$items[artikelnum]] as $items2) {
$groesse[] = "$items2[artikelnum]";
}
$smarty->assign('groesse', $groesse);
$smarty->display('artikel.html');
#print_r($groesse) . "<br><br>";
$groesse = "";
}
[/php:1:ed71f6dab1]
genau hier is der fehler, du musst das assign und display außerhalb vom foreach machen (außer das foreach wird nur einmal durchlaufen, was ich ja nicht annehme)
mfg Thomas _________________ Oppossom - Heavy rock from austria |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|