php制作简单模版引擎(2)

<?php //设置字符编码UTF-8 header('Content-Type:text/html;charset=utf-8'); //网站根目录 define('ROOT_PATH',dirname(__FILE__)); //存放模版文件夹 define('TPL_DIR',ROOT_PATH.'/Templates/'); //编译文件夹 define('TPL_C_DIR',ROOT_PATH.'/Templates_c/'); //缓存文件夹 define('CACHE',ROOT_PATH.'/Cache/'); //系统变量配置目录 define('CONFIG',ROOT_PATH.'/Config/'); //是否开启缓冲区 define('IS_CACHE',false);//false //判断是否需要开启 IS_CACHE ? ob_start() : null; //引入模版类 require ROOT_PATH.'/Class/Templates.class.php'; //实例化模版类 $_tpl=new Templates(); $_tpl->display('index.tpl'); ?>

templates/index.tpl

<!DOCTYPE html> <html lang="zn-cn"> <head> <meta charset="UTF-8"> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <meta content=""> <meta content=""> <meta content=""> <meta content=""> <title><!-- {WebName} --></title> <link type="text/css" href="https://www.jb51.net/css/bootstrap.min.css"> <link type="text/css" href="https://www.jb51.net/css/style.css"> </head> <body> <!-- {#}php注释{#} --> <!-- {if $a} --> 123 <!-- {else} --> 321 <!-- {/if} --> <br /> <!-- {foreach $array(key,value)} --> <!-- {@key} -->...<!-- {@value} --><br /> <!-- {/foreach} --> 系统变量<!-- {WebName} --><br /> 普通变量<!-- {$name} --><br /> <script src="https://www.jb51.net/js/jquery-2.2.1.min.js" type="text/javascript"></script> <script src="https://www.jb51.net/js/bootstrap.min.js" type="text/javascript"></script> <script type="text/javascript"> </script> </body> </html>

config/config.xml

<?xml version="1.0" encoding="UTF-8"?> <root> <taglib> <name>WebName</name> <value>XXX网站</value> </taglib> </root>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/f1fb968ef626dc7536c294959ff126df.html