dwoo / dwoo
此包已被弃用且不再维护。作者建议使用 twig/twig 包。
Dwoo 是一个 PHP5/PHP7 模板引擎,它几乎完全兼容 Smarty 模板和插件,但它是为 PHP5 从头开始编写的,并添加了许多功能。
1.3.7
2018-04-18 14:25 UTC
Requires
- php: ^5.3|^7.0
Requires (Dev)
- phpunit/phpunit: 4.8.27
README
Dwoo 是从 2008 年初开始的一个 PHP5/PHP7 模板引擎。这个想法源于这样一个事实:众所周知,模板引擎 Smarty 正在变得越来越旧。它承载着它年龄的重量,拥有与较新版本不一致的旧功能,它是为 PHP4 编写的,其面向对象的方面没有充分利用 PHP5 在该领域的更先进功能,等等。因此,Dwoo 诞生了,希望提供一个更现代、更强大的引擎。
到目前为止,它在许多方面已经证明比 Smarty 更快,并提供了兼容层,允许多年来一直使用 Smarty 的开发者逐步将他们的应用程序迁移到 Dwoo。
Dwoo 1.3.x 兼容 PHP 5.3.x 到 PHP 7.x
文档
获取最新版本的 Dwoo 网站:http://dwoo.org/
wiki/文档页面可在 http://dwoo.org/documentation/ 获取
要求
- PHP >= 5.3
- PHP >= 7.0
- 多字节字符串
许可证
Dwoo 在 GNU LESSER GENERAL PUBLIC LICENSE V3 许可证下发布。
快速入门 - 运行 Dwoo
基本示例
<?php // Include Composer autoloader require __DIR__ . '/vendor/autoload.php'; // Create the controller, this is reusable $dwoo = new Dwoo\Core(); // Load a template file (name it as you please), this is reusable // if you want to render multiple times the same template with different data $tpl = new Dwoo\Template\File('path/to/index.tpl'); // Create a data set, if you don't like this you can directly input an // associative array in $dwoo->get() $data = new Dwoo\Data(); // Fill it with some data $data->assign('foo', 'BAR'); $data->assign('bar', 'BAZ'); // Outputs the result ... echo $dwoo->get($tpl, $data); // ... or get it to use it somewhere else $dwoo->get($tpl, $data);
循环示例
<?php // To loop over multiple articles of a blog for instance, if you have a // template file representing an article, you could do the following : require __DIR__ . '/vendor/autoload.php'; $dwoo = new Dwoo\Core(); $tpl = new Dwoo\Template\File('path/to/article.tpl'); $pageContent = ''; $articles = array(); // Loop over articles that have been retrieved from the DB foreach($articles as $article) { // Either associate variables one by one $data = new Dwoo\Data(); $data->assign('title', $article['title']); $data->assign('content', $article['content']); $pageContent .= $dwoo->get($tpl, $data); // Or use the article directly (which is a lot easier in this case) $pageContent .= $dwoo->get($tpl, $article); }