7 Star 19 Fork 5

mr小卓X / Wetpl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Wetpl

这是一款超小型的php模板引擎,代码只有16KB!

在开发了Lolly框架之后,我把它运用到了开发中!但是Lolly自带的模板引擎Lytpl功能太少,于是就写了这个模板引擎!

Wetpl和Lytpl有一些代码是一样的,只不过Wetpl功能更多,更轻量!

Demo

{% import html/head.html %}

{% #使用import可以导入其他的模板 %}

{% # 下面是一个简单的个人信息例子! %}

{% go conf %}

<p>我被跳过了!</p>

{% point conf: %}

<p>我的名字:{% $conf['name'] %}</p>

<p>我的年龄:{% $conf['age'] %}</p>

<p>
    我的爱好:
    {% loop $v in $conf['hobby'] %}

    {% $v %}

    {% end %}
</p>

<p>一段介绍:{% $conf['about'] %}</p>

<hr>

{% # 下面介绍一下其它东西 %}

{% func demo1(): echo '我是一个函数,我的名字叫做"demo1",我会自己说话';  %}

{% func demo2(): return '我是一个函数,我的名字叫做"demo2",我不会自己说话,只有你让我说话时我才能说话';  %}

<p>{% demo1() %}</p>
{% # 上面的在调用之后会自己输出 %}

<p>{% &demo2() %}</p>
{% # 如果想输出他的返回值的话,只需要在前面加上'&' %}

{% # 下面是关于赋值的操作 %}
{% % demo2() to $demo2_val %}
{% % $demo2_val to $demo2_val_2 %}
{% % 1 to $n %}
{% #Ps:赋值的前面要有'%' %}

{% % $a = 1 %}
{% % $a += 1 %}
{% # 使用这种方法赋值也是可以的,更简单 %}

{% #类似于 $n += 1 ('+'可以为 +、-、*、/、.) %}
{% % 1 to + $n %}


<hr>

{% #最重要的判断语句 %}

{% % 1 + 1 * 1 to $num %}

{% if $num == 1 %}
    if:1 + 1 * 1 = 1!
{% elif $num == 3 %}
    elif了:1 + 1 * 1 = 3!
{% else %}
    else: 1 + 1 * 1 = {% $num %}!
{% end %}

<hr>

{% #还有循环 %}

<p>
    {% for $i = 0;$i < 10;$i++ %}
    for:{% $i + 1 %}
    {% end %}
</p>

<p>
    {% % 0 to $j %}
    {% while $j < 10 %}
        while:{% $j + 1 %}
        {% % 1 to + $j %}
    {% end %}
</p>

<p>
    {% % [1,2,3,4,5] to $arr %}
    {% loop $key,$val in $arr %}
    {% $key %} => {% $val %}
    {% end %}
</p>

<p>
    {% loop $value in $arr %}
    {% $value %}
    {% end %}
</p>

<p>
    {% # 如果需要用到其他东西,可以使用php:直接运行php代码 %}

    {% php: echo "通过直接运行php输出"; %}
</p>

{% import html/tail.html %}

Wetpl可以被用于任何地方,在使用时你只需要一个函数:

echo Wetpl::render('html/demo.html',['xxx' => 'xxx']);

第一个参数是文件位置,第二个是传过去到变量,另外第三个和第四个是可选的,分别是左分隔符和右分隔符!

MIT License Copyright (c) 2020 mr小卓X Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一款超小型的php模板引擎,只有一个函数! 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/mrxzx/Wetpl.git
git@gitee.com:mrxzx/Wetpl.git
mrxzx
Wetpl
Wetpl
master

搜索帮助