定制 irfantoor/template-engine 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

irfantoor/template-engine

Composer 安装命令:

composer require irfantoor/template-engine

包简介

A simple, small and smart template engine

README 文档

README

A simple and small template engine.

Quick start

Installation

Installation or inclusion in your project:

$ composer require irfantoor/template-engine

To test the template engine:

$ vendor/bin/test

Creating the Template Engine:

$te = new IrfanTOOR\TemplateEngine([
    'max_depth' => 3, # defaults to 3
    'base_path'  => 'your/path/to/template/files/',
]);

Processing Text

$text = "{$greeting} {$user}!";
$data = [
    'greeting' => 'Hello',
    'user' => 'World',
];

echo $te->processText($text, $data);

Processing File

# home.php
<h1>{$title}</h1>

<ul>
{@foreach ($list as $item):}
<li>{$item}</li>
{@endforeach}
</ul>
$data = [
    'title' => 'Fruits',
    'list' => [
        'Apple',
        'Orange',
        'Blackberry',
        'Raspberry',
    ],
];

echo $te->processFile("home.php", $data);

Template

Comments

format: {#...}

{# its a comment!}
{#anything here including the external brackets are removed from the output}

Tokens

format: {$...}

The tokens are replaced with the values provided by the passed data array.

{$name['first']} {$name['last']}
{$address[0]}
{$address[1]}
tel: {$tel}
email: {$email}

format: {!$...} The tokens are replaced with tags are replaced with value, without doing any html special character conversion. It helps in including the html tags etc. which are displayed as html and not as content.

Commands

format: {@...}

{@include 'header.php'}

{@echo date('d-m-Y')}

{@if ($list):}
    # Note: you can use the curley brackets, so use the form foreach (...): endforeach instead
    {@foreach ($list as $k => $v):}
    data provided is : {$k} | {$v}
    {@endforeach}
{@endif}



# you can define the data in the template
{@ $d = date('d-m-Y')}

# and prints ...
date : {$d}

# Note: The statement in {@ ...} tags need not to be terminated with a semicolon ';'
{@ $list = [
    'black',
    'white'
]}

dump list:
# Note: The variable to dump, might as well be an object, array, bool int or a string
{$list}

Note: after {@ use the commands as if you were using the php code, though only constraint is that you can not use the loops or commands using the curly brackets.

统计信息

  • 总下载量: 48
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固