I'm not much into templates, but here is what would I do:
$dir=opendir("../news");
$s = "";
while ($file2 = readdir($dir)) {
if (substr($file2,-4)==".txt"){
$s .= "<option value=\"$file2\">$file2\n";
}
}
$tpl->assign("dirlist", $s);
closedir($dir);
<form method="post" action="pickstory.php">
<select size="15" name="picker">
{dirlist}
</select>
<input type="Submit" value="Add Article">
</form>
Can this work with templates like i'm trying, or is there a better way?
There is a better way, because templates support looping, but I don't know much about this stuff. I can try, though:
$dir=opendir("../news");
$s = "";
while ($file2 = readdir($dir)) {
if (substr($file2,-4)==".txt"){
$tpl->assign("dir", $file2);
$tpl->parse("dirlist", ".diropts");
}
}
closedir($dir);
dirlist.tpl:
<option value="{dir}">{dir}
Main TPL file:
<select size="15" name="picker">
{diropts}
</select>
<input type="Submit" value="Add Article">
</form>
This may be good, near-good or completely wrong. :-)
By the way, consider using
if (eregi(".txt$", $file2))
instead of
if (substr($file2,-4)==".txt")
Hope this helped.