class/parser.class.php
<?php class Template{ var $sSource; var $sParsed; function load($sTemplate) { } function init($sKey, $sValue) { $this->aValues[$sKey] = $sValue; } function run() { } } ?>
plik strony głównej tak
<? include('config.php'); include('inc/news.inc.php'); $tpl = new Template; $tpl -> load(TPL_DIR.'index.tpl'); $tpl -> init('{categorie}', category($id)); $tpl -> run(); ?>
a plik inc/news.inc.php tak:
<?php //...skrypt function category($id) { $id = (int) $id; $get = "select art_id, art_title, art_text, user_id, art_comments from $artSQL where art_topic = '$id' order by art_data asc"; $query = $db->query($get); $num = $db->num_rows($query); if($num > 0) { while($obj = $db->fetch_object($query)) { $tpl -> load(TPL_DIR.'art/art_in_cat.tpl'); $tpl -> init('{title}', $obj->art_title); $tpl -> init('{text}', $obj->art_text); $tpl -> init('{poster}', $user->username($obj->user_id)); $tpl -> init('{comments}', '<a href="comments.php?what=art&id='.$id.'>skomentuj ['.$obj->art_comments.']</a>'); $tpl -> init('{read}', '<a href="art.php?id='.$obj->art_id.'>czytaj</a>'); $tpl -> run(); } } else { return 'w tej katagorii nie wystepuja zadne artykuly'; } } // .....skrypt ?>
i teraz gdy jest ta petla to nie wczytuje calego szablonu index.tpl do konca a jedynie sam początek i później art/art_in_cat.tpl i to już koniec wczytania szablonu, i tylko jeden wynik sie pokazuje zamiast wszystkich co są w kategorii. jak to naprawić bo niestety pierwszy to taki moj parser, zawsze sie bawilem ze dawalem kodzie thema <? newsy() ?> itp i bylo dobrze,