cobbdb/eta

轻量级的PHP模板引擎。

v2.0.7 2016-10-15 21:34 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:41:43 UTC


README

为快速原型和小型Web应用程序设计的轻量级PHP模板引擎。

composer require cobbdb/eta

Latest Stable Version Monthly Downloads License

希腊字母大写字母eta的符号是H。在数学中,eta常被用作效率的符号。

该引擎专为需要快速开发和部署且设置最少的原型和小型Web应用程序而设计。由于Eta不使用自定义模板标签,项目可以在未来轻松过渡到更健壮的框架,如Cake或Yii。

安装

  • 将此文件复制到您选择的目录中,并在使用Eta的文件中添加require_once。
  • Eta的默认目录为./,但可以通过H::setHome()进行更改。
  • Eta的默认页面模板为./base.view,但可以通过H::setBase()进行更改。

用法

以下是一个简单的“Hello World”示例
// index.php
require_once "H.php";
$who = "World";
echo H::render(null, [
    "name" => $who
]);
// base.view
Hello <?= $name ?>!
模板包含示例
<div id="myWidget">
    <?= H::render("neat/widget.html") ?>
</div>

render(path, [model], [grounded])

渲染模板而不自动响应。

参数

  • {String} path - 模板路径或null使用基本模板。
  • {Array} [model] - 注入模板的数据。
  • {Boolean} [grounded] - False使用字面路径并绕过主目录。

返回值 {String}
抛出 {MissingTemplateException}

// The 'grounded' argument can bypass the home directory
$myView = H::render("../my/template.html", [], false);

setHome(path, [remember])

设置新的默认视图目录。

参数

  • {String} path
  • {Boolean} [remember] - True保留为reset()使用的默认目录。
// Default is the same directory in which eta.php file is placed.
H::setHome("/path/to/my/templates/");

setBase(path)

设置新的默认基本页面模板。

参数

  • {String} path - 新基本模板的完整路径。
// Default is ./base.view
H::setBase("/path/to/myBase.html");
// Now H::render(null) will use a new base template!

reset()

将Eta重置为默认主目录。

// Use special templates directory temporarily.
H::setHome("../path/to/other/templates/");
H::render("some/newThing.tpl");
H::render("and/another/template.html");
// Now reset home back to default for rest of project!
H::reset();

作者:Dan Cobb:cobbdb@gmail.com - petitgibier.sytes.net
许可证:MIT