##**模版引擎**
**(以下第一个---->理解为变量未缓存编译结果,第二个为缓存后结果)**
**(配置以默认为准)**
###*模版配置*
* * * * *
~~~
$template_config = [
// 模板引擎标签开始标记
'left_delim' => '<{',
// 模板引擎标签结束标记
'right_delim' => '}>',
];
~~~
###*方法*
* * * * *
~~~
/**
* 模版编译
*
* @param string $content 模版内容
* @param array $data 模版变量
* [
* key=>['cache'=>bool,'value'=>miexd]
* ,...
* ]
* @param array $language 语言变量
* [
* key=>'value'
* ,....
* ]
*
* @return string
*/
\msqphp\core\template\Template::commpile(string $content, array $data = [], array $language = []) : string
~~~
###*注意事项*
* * * * *
+ 左标签后禁止带有空格,左标签最好正常闭合,不然会有未知问题
> <{ a错误
> <{$a } 错误,未闭合
> <{a}> 正确
+ 右标签前可有空格
> a }>允许
+ 如果可输入空格,则一般支持多个空格
+ foreach等可以省略部分空格,但不推荐
> <{foreach $array as $key=>$val}>
> <{if $a===$b}>
+ 推荐左标签: <{ , 右: }> ,暂时不与html或css或js冲突
+ 数据缓存为真实缓存
>相当于将所有指定缓存数据所参与的所有语句(if,foreach等等)进行预编译
>使得编译后内容展示的时候不需要缓存数据(半成品)
+ 支持标签嵌套,但不推荐
###*变量赋值:*
* * * * *
~~~
$a = 'value';
//模版内容 ----> 变量不缓存 ----> 变量缓存
<{$a}> ----> <?php echo $a;?> ----> value
~~~
###*数组赋值:*
* * * * *
支持php数组写法和以.分割两种写法,无限维数
~~~
$a = ['name'=>'user','pass'=>test',0=>'a'];
<{$a.name}> ----> <?php echo $a['name'];?> ----> user
<{$a['name']}> ----> <?php echo $a['name'];?> ----> user
<{$a.0}> ----> <?php echo $a[0];?> ----> a
<{$a[0]}> ----> <?php echo $a[0];?> ----> a
~~~
###*引入文件*
* * * * *
引入文件后按模版引擎解析,文件不存在报错
~~~
<{include file_path}>
/**
* @example
*/
<{include ......../resources/templates/home/user/top.tpl}>
~~~
###*语言*
* * * * *
**不存在抛出异常**
**解析时不分语言,在传参时区分**
~~~
$lang = [
'username' => '用户名'
];
$lang_english = [
'username' => 'username'
];
<{language.username}> = <{lang.username}>
中----> '用户名'
英----> username
~~~
###*常量*
* * * * *
**不存在抛出异常**
**直接替换为对应值**
~~~
<{cont.usernam}>
<{constant.usernam}>
~~~
###*foreach:*
* * * * *
支持写法:
~~~
<{foreach $array as $key => $value}>
<{foreach $array as $value}>
<{endforeach}>
<{/endforeach}>
~~~
例:
~~~
$arr = [1,2,3,4,5,6,7,8];
<{foreach $arr as $k => $v}>
<{$k}>:<{$v}>.
<{endforeach}>
---->
<?php foreach($arr as $v) :?>
<?php echo $k;?>:<?php echo $v;?>.
<?php endforeach;?>
---->
0:11:22:33:44:55:66:77:8
~~~
###*if*
* * * * *
支持写法
~~~
//比较符支持:===,!==,==,!=,>,<,>=,<=,<>,
//变量比较固定值,支持数字,字符串,布尔
<{if $a == 'string'}>
<{if $b === 0}>
//两个变量比较
<{if $a === $b}>
<{elseif ....同上}>
<{else}>
<{endif}>
<{/endif}>
~~~
例:
~~~
$a = true;
<{if $a === true}>
成功
<{endif}>
---->
<?php if($a===true) : ?>
成功
<?php endif;?>
---->
成功
~~~
###*例*
~~~
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title></title>
<link href="<{constant.CSS}>reset.css" rel="stylesheet" type="text/css" />
<link href="<{constant.CSS}>style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<{constant.JS}>jquery-2.1.1.min.js"></script>
</head>
<body>
<form class="login_form" method="post" action="user/login">
<label class="msq-icon" for="username">
</label><input type="text" name="username" placeholder="<{lang.username_info}>" required="required" autofocus="autofocus" />
<label class="msq-icon" for="password">
</label><input type="password" name="password" placeholder="<{lang.password_info}>" required="required" minlength="6" maxlength="16" />
<input type="checkbox" name="auto_login" checked="checked " alt="<{lang.auto_login}>" title="<{lang.auto_login}>"/>
<label for="auto_login" alt="<{lang.auto_login}>" title="<{lang.auto_login}>"><{lang.auto_login}></label>
<input type="submit" value="<{lang.login}>"/>
</form>
</body>
</html>
//编译后----------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title></title>
<link href="www.example.com/css/reset.css" rel="stylesheet" type="text/css" />
<link href="www.example.com/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="www.example.com/js/jquery-2.1.1.min.js"></script>
</head>
<body>
<form class="login_form" method="post" action="user/login">
<label class="msq-icon" for="username">
</label><input type="text" name="username" placeholder="邮箱/手机/用户名" required="required" autofocus="autofocus" />
<label class="msq-icon" for="password">
</label><input type="password" name="password" placeholder="请输入密码" required="required" minlength="6" maxlength="16" />
<input type="checkbox" name="auto_login" checked="checked " alt="下次自动登录" title="下次自动登录"/>
<label for="auto_login" alt="下次自动登录" title="下次自动登录">下次自动登录</label>
<input type="submit" value="登录"/>
</form>
</body>
</html>
~~~
- 序言
- 框架
- 框架获取
- 框架安装
- 应用结构
- 框架结构
- 应用目录结构
- 框架流程
- 命名规范
- 核心思想
- 扩展
- 类组装
- 框架基类
- Arr
- Arr扩展函数
- Date基类
- Dir
- Dir基类扩展函数
- Dom基类
- File基类
- Str基类
- Str随机字符
- Str操作函数
- Str随机创建
- Html基类
- Header基类
- Filter基类
- 框架核心
- 路由
- 路由信息
- 路由安装样本
- 路由逻辑原理
- 路由方法匹配
- 路由分组
- 路由构建
- 路由限制
- 路由规则
- 路由多语,多主题
- 路由常量
- 路由扩展
- 路由例
- 路由真静态使用
- 智能加载
- Response基类
- 定时任务
- 框架主类
- 控制器
- model
- model样本
- model使用
- view
- view路径
- view方法
- view配置
- view使用
- view真静态
- view例
- view多主题
- 模版引擎
- 模版引擎之单句解析
- 模版引擎之foreach解析
- cache
- cache注意事项
- cache配置
- cache方法
- cache使用
- cache扩展
- cache处理类File配置
- cache处理类Apc,Apcu配置
- cache处理类memcache,memcached配置
- cookie
- session
- 框架扩展
- Upload类
- 测试
- 测试流程
- 测试文件编写
- 测试文件例-数组篇
- 测试类函数
- 测试类使用
- 测试注意事项
- 常用功能
- 读码须知
- 个人技巧或习惯
- 万能get,call,callStatic
- &&和||
- 变量值交换
- trait拼接
- 多语支持