kolserdav/templater

简单的模板引擎

v2.0.11 2018-06-12 11:47 UTC

This package is not auto-updated.

Last update: 2024-09-27 15:06:46 UTC


README

简单模板引擎
该组件具有客户端缓存功能,可离线访问已访问页面。

安装

~$ composer require kolserdav/templater

依赖关系

"php" : "^7.0"
"kolserdav/router": "^0.2.0"
--dev "phpunit" : "^7.0"

package.json "dependencies": { "ajaxsim": "^1.0.0", "dist-cookie": "^0.0.7" }, "devDependencies": { "webpack": "^4.5.0"

Component templater使用kolserdav/router模块,工作项目必须使用单点访问。有关kolserdav/router模块的设置,请参阅:https://github.com/kolserdav/router

在模板中使用

目前支持以下结构

{{ variable }}  //some variable need sent to render(['variable' => 'value'],[])
 
{% field %}  //HTML block field, need sent to render([],['field' => 'path/patch.file.html'])

{% for value in array %}{{ value }}{% endfor %} //for in, need sent to render(['for_array' => [1,2,3])  

要启用IDE中的语法高亮,您可以使用.twig扩展。

使用标签进行支持结构。例如

{% for value in array %}<h3>{{ value }}</h3><br>{% endfor %}

为了正确工作,名称'value'对于一页必须是唯一的,并且必须在一行中写入。例如

{% for value1 in array_one %}{{ value1 }}{% endfor %}

{% for value2 in array_two %}{{ value2 }}{% endfor %}

使用

要使用此模块,需要在您的索引文件或控制器文件中写入一些依赖项...

可选(如果您需要页面缓存)

use Avir\Templater\Module\Config;

$config = new Config();
$config->setConfig([
    'cache' => '/path/cache/catalog/+{pages}' //default : false  {pages} - auto create catalog
    'userCache' => '/path/usrCache/catalog/+{users}' //default : false {users} - auto create catalog
]);

必需(包括模板)

use Avir\Templater\Module\Render;

$obj = new Render('/path/template/catalog', '/template.file'); 
$obj->render(
    [
        'first_variabe' => 'string', //{{ key }} 
        'second_variable' => 111,
        'for_array1' => [1,2,3,4], //arrays need have 'for_' before
        'for_array2' => [4,3,2,1]
    ],
    [
        'field1' => 'patch.file', //patches repository /template-catalog/views
        'field2' => 'path/patch.file' //patches repository /template-catalog/views/path
        ]);

它正常工作。