bonfim/tpl 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

bonfim/tpl

Composer 安装命令:

composer require bonfim/tpl

包简介

Gerenciador de Templates PHP

README 文档

README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Table of Contents

Prerequisites

  • PHP 7.1+

Installation

$ composer require EdsonOnildoJR/PHP-Template-Engine

Basic usage

Create an index.php file and require the autoload.php of composer

<?php

include 'vendor/autoload.php';

After that, let's to do all necessary configuration

use Sketch\Tpl;

Tpl::config([
    //'environment' => 'production',
    'environment'   => 'development',
    'template_dir'  => 'path/to/templates',
    'cache_dir'     => 'path/to/caches'
]);

Assign and render template

Tpl::assing('title', 'Hello!');
Tpl::render('test');

Sketch Tags

Variables

Variables are the dynamic content of the template, valorized on the execution of the script with Tpl::assing() static method. Variables names are case sensitive.

Template:

Welcome to {title}

Data:

<?php

Tpl::assign('title', 'Sketch');

Output:

Welcome to Sketch

Modifiers on variables

You can add modifiers that are executed on the variables.

Template:

Hello {name|capitalize}!

Data:

<?php

Tpl::assign('name', 'edson onildo');

Output:

Hello Edson Onildo!

Conditional Expression

Checks an expression and print the code between {if}{else} if the conditions is true or {else}{/if} if the condition is false. Try to use nested blocks :)

Template:

{if age >= 18}
    Adult
{else}
    Minor
{/if}

Data:

<?php

Tpl::assign('age', 19);

Output:

Adult

you can also use the {if condition}content{elseif condition}content{else}content{/if} or any combination of if and else.

Loop

Allow to loop through the value of arrays or objects.

Template:

<ul>
    {loop authors as author}
    <li>
        {author.name}: {author.page}
    </li>
    {/loop}
</ul>

Data:

<?php

$authors = [
    [
        'name' => 'Edson Onildo',
        'page' => 'https://github.com/EdsonOnildoJR'
    ],
    [
        'name' => 'Contributors',
        'page' => 'https://github.com/EdsonOnildoJR/Sketch/contributors'
    ]
];

Tpl::assign('authors', $authors);

Output:

Edson Onildo: https://github.com/EdsonOnildoJR
Contributors: https://github.com/EdsonOnildoJR/Sketch/contributors

Function

Use {func funcname()} tag to execute a PHP function and print the result. You can pass strings, numbers and variables as parameters.

Template:

{func date('Y')}

Output:

2018

Include

With {include 'template'} tag you can include external template as blocks.

Template:

<h1>New user:</h1>
{template 'userForm'}

Output:

<h1>New user:</h1>
<form class="user" action="" method="post">
    ...
</form>

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email inbox.edsononildo@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固