|
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 |
Philipp_Frank Smarty Rookie
Joined: 24 Oct 2004 Posts: 6
|
Posted: Sun Oct 24, 2004 9:31 pm Post subject: While-Schleife |
|
|
Hi, ich habe folgendes Problem:
Ich nutze diesen Code um alle ordner/dateien aus einem Ordner auszulesen und in ein selectfeld zu schreiben:
Code: | <?PHP
if ($dir = @opendir("EXTgalerie/galerien/")) {
while (($file = readdir($dir)) !== false) {
if($file != ".." && $file != ".")
$filelist[] = $file;
}
closedir($dir);
}
asort($filelist);
while (list ($key, $val) = each ($filelist))
echo "<option value=\"$val\">$val</option>";
?> |
Wie mache ich das denn nun in einem template. Bin noch neuling im Bezug auf smarty |
|
Back to top |
|
b166-er Smarty Rookie
Joined: 22 Oct 2004 Posts: 29 Location: Germany, Wiesbaden
|
Posted: Mon Oct 25, 2004 5:13 am Post subject: |
|
|
bei diesem beispiel is-es gaaanz einfach
hier schau ma:
erstma deine php-datei:
[php]<?php
...
$smarty_obj = new Smarty; // hier erstma Smarty instanzieren
...// dann noch paar configs an Smarty uebergeben
// hier kommt dein code
if ($dir = @opendir("EXTgalerie/galerien/")) {
while (($file = readdir($dir)) !== false) {
if($file != ".." && $file != ".")
$filelist[]['name'] = $file;
}
closedir($dir);
}
asort($filelist);
// jetzt einfach die liste mit dateien an smarty uebergeben:
$smarty_obj->assign('ordnerliste',$filelist);
// und letzten endes, das template anzeigen.
$smarty_obj->display('index.tpl');
?>[/php]
jetzt das template, index.tpl:
Code: | ... // html-code
{section name=f1 loop=$ordnerliste}
<option value="{$ordnerliste[f1].name}">{$ordnerliste[f1].name}</option>
{/section}
|
thats it!
das ist eine von vielen methoden...
viel spass, cu
________
COLORADO DISPENSARY |
|
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
|