- 论坛徽章:
- 0
|
原帖由 gg5g321 于 2006-4-4 08:21 发表
嗯,PHP与HTML分离...只能说,各人需求不同...但我觉得这个是必要的.
结合实际应用...在同一个模板里..根据实际情况,很多时候要显示不同的HTML代码...
难道将这些HTML代码写进PHP代码里???
为什么很多模板类 ...
那也很简单啊。。。不需要在HTML里加任何PHP代码。只要在你想显示不同的HTML代码的开始处设个开始标识符,在结束处设个结束标识符。然后在PHP文件里判断,根据判断结果进行不同的替换!!
我就拿PHPLIB模板来举例吧:
主模板index.htm
<!-- BEGIN show -->
这里可以预先随便放一个部分的内容,
当然放最有可能显示的那个部分最好了!。
<!-- END show -->
/********* show1.htm show2.htm show3.htm为你要选择显示内容!*********/
主文件index.php
<?php
include "template.php";
$who_is_show=2;
$tpl=new template("templates");
$tpl->set_file("index","index.htm");
$tpl->set_block("index","show","showme");
switch ($who_is_show)
{
case 1:
$tpl->set_file("show1","show1.htm");
$tpl->parse("contentshow","show1");
$content=$tpl->get("contentshow");
$tpl->set_var("showme",$content);
break;
case 2:
$tpl->set_file("show2","show2.htm");
$tpl->parse("contentshow","show2");
$content=$tpl->get("contentshow");
$tpl->set_var("showme",$content);
break;
case 3:
$tpl->set_file("show3","show3.htm");
$tpl->parse("contentshow","show3");
$content=$tpl->get("contentshow");
$tpl->set_var("showme",$content);
break;
default:
break;
}
$tpl->pparse("output","index");
?>
[ 本帖最后由 ultralqxq 于 2006-4-5 15:10 编辑 ] |
|