intellishop / dwooeight
Dwoo Eight 是 dwoo 模板引擎的 PHP8 兼容分支。
1.0.1
2023-05-10 11:50 UTC
Requires
- php: 7.*|8.*
Requires (Dev)
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.x
- PHP >= 8.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); }