daVro/fabrication

基于DOM的模板引擎,没有占位符!

1.10 2024-06-14 14:20 UTC

This package is auto-updated.

Last update: 2024-09-12 22:14:51 UTC


README

简介

基于文档对象模型的PHP模板引擎。

FabricationEngine 引擎与市场上大多数其他模板引擎不同,主要因为它没有占位符的概念,它只关注元素和属性、结构、表达式以及需要处理的内容的指令。

结构是模板,表达式是文档对象模型中包含的元素的路径。FabricationEngine 在许多方面扩展了PHP内置的DOMDocument,并允许原生使用XPath对象。这使得模板引擎非常灵活且可扩展。

您可以通过加载HTML、XHTML、XML字符串或简单地加载文件来创建DOM结构,或者您可以使用原生的DOMDocument API构建自己的文档结构。此外,还有一个具有递归创建结构的能力的特定方法。还有一些高级数据集模板功能。

功能

无占位符的模板。数据集模板。

文档

示例:分配键值对并输出。

简单的输入/输出示例。

文档示例,分配

<?php

$engine = new Fabrication\FabricationEngine();
$engine->input('hello', 'world');

echo $engine->output('hello');
#
# world
#

?>

示例:分配ID #键值对。

ID键会自动映射到匹配标识符的DOM元素。

文档示例,按ID分配

<?php

$template = '<html><head></head><body><div id="hello"></div></body></html>';

$engine = new Fabrication\FabricationEngine();
$engine->input('#hello', 'world');

$engine->run($template);

echo $engine->output('#hello');
#
# world
#

echo $engine->saveHTML();
#
# <html><head></head><body><div id="hello">world</div></body></html>
#

echo $engine->saveFabric();
#
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
#    "http://www.w3.org/TR/html4/loose.dtd">'.
# <html><head></head><body><div id="hello">world</div></body></html>
#

?>

示例:输入类.key,键值对。

类键会自动映射到匹配类标识符的元素。

<?php

$template = '<html><head></head><body><div class="hello"></div></body></html>';

$engine = new Fabrication\FabricationEngine();
$engine->input('.hello', 'world');

$engine->run($template);

echo $engine->output('.hello'); 
#
# world
#

echo $engine->saveHTML();
#
# <html><head></head><body><div class="hello">world</div></body></html>
#

echo $engine->saveFabric();
#
# <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
#    "http://www.w3.org/TR/html4/loose.dtd">'.
# <html><head></head><body><div class="hello">world</div></body></html>
#

?>

文档示例。

分配元素.

分配性能.

创建.

Composer和标记说明。

https://packagist.org.cn/packages/davro/fabrication

$ git tag 1.0.5 $ git tag 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5

$ git push --tags Total 0 (delta 0), reused 0 (delta 0) To https://github.com/davro/fabrication.git

  • [new tag] 1.0.5 -> 1.0.5

在GitHub上标记分支也将通知packagist.org更新到新标记。

贡献者

许可

Fabrication Engine采用LGPL许可发布。