roolith/template-engine 问题修复 & 功能扩展

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

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

roolith/template-engine

最新稳定版本:1.0.4

Composer 安装命令:

composer require roolith/template-engine

包简介

PHP simple template engine

README 文档

README

No overcomplicated stuff! Just plain PHP in template file. No eval, it uses output buffering!

Install

composer install roolith/template-engine

Usage

$view = new \Roolith\Template\Engine\View(__DIR__ . '/views');

try {
    $data = [
        'content' => 'home content',
        'title' => 'home page',
    ];

    echo $view->compile('home', $data);
} catch (\Roolith\Template\Engine\Exceptions\Exception $e) {
    echo $e->getMessage();
}

views folder contains -

home.php
partials/header.php
partials/footer.php

Where home.php

<?php $this->inject('partials/header') ?>

    <p><?= $this->escape('content') ?></p>

<?php $this->inject('partials/footer') ?>

header.php

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title><?= $this->escape('title') ?></title>
    <link rel="stylesheet" href="<?= $this->url('assets/app.css') ?>">
</head>
<body>

footer.php

    <script src="<?= $this->url('assets/app.js') ?>"></script>

</body>
</html>

You may use escape method or just print variable as plain

<title><?= $this->escape('title') ?></title>

or

<title><?= $title ?></title>

inject method allows to inject another view

$this->inject('partials/footer')

For nested call

$view->compile('nested.template', $data);

It will look for nested folder and template.php file.

Expected unit test result

$ ./vendor/bin/phpunit --testdox tests --stderr
PHPUnit 9.6.23 by Sebastian Bergmann and contributors.

View
 ✔ Should set view folder
 ✔ Should escape variable
 ✔ Should add slash before url
 ✔ Should compile view file
 ✔ Should compile nested view file

Time: 00:00.009, Memory: 4.00 MB

OK (5 tests, 11 assertions)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固