代码: |
<?php require('./template.php'); //由html生成的php文件的前缀,区别使用多种风格. $tpl_prefix = 'default'; //模板文件名 $tpl_index = 'index'; $tpl = new Template($tpl_prefix); $cats = array( array('forum_id'=>'1','forum_cat_id'=>'0','forum_name'=>'PHP学习'), array('forum_id'=>'2','forum_cat_id'=>'0','forum_name'=>'MYSQL学习') ); $forums = array( array('forum_id'=>'3','forum_cat_id'=>'1','forum_name'=>'PHP高级教程'), array('forum_id'=>'4','forum_cat_id'=>'1','forum_name'=>'PHP初级教程'), array('forum_id'=>'5','forum_cat_id'=>'2','forum_name'=>'MYSQL相关资料') ); if ($cats) { if ($tpl->chk_cache($tpl_index))//检查判断是否需要重新生产PHP模板文件. { $tpl->load_tpl($tpl_index);//加载html模板文件. //替换PHP语句 $tpl->assign_block("{block_cat}","<?foreach(/$cats as /$cat) {?>"); $tpl->assign_block("{/block_cat}","<?}?>"); $tpl->assign_block("{block_forum}","<?foreach(/$forums as /$forum) { /nif(/$forum['forum_cat_id'] == /$cat['forum_id']) {?>"); $tpl->assign_block("{/block_forum}","<?}/n}?>"); //生产PHP模板文件. $tpl->write_cache($tpl_index); } } //包含PHP模板文件. include($tpl->parse_tpl($tpl_index)); ?> |
代码: |
{block_cat} <table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#000000" align="center"> <tr align="{=TR_ALING}" bgcolor="#FFFFFF"> <td colspan="6"><span class="title"><b>{=$cat['forum_name']}</b></span></td> </tr> {block_forum} <tr bgcolor="#FFFFFF"> <td valign="top">{=$forum['forum_name']}</td> </tr> {/block_forum} </table> <br> {/block_cat} |
新闻热点
疑难解答