考虑将模板系统用于新项目,它只是一个很小的站点,并且不想使用smarty的开销和复杂性".我真的不喜欢模板系统会强迫您使用另一种语言,只是使设计人员(显然)更容易.
Looking at using a template system for a new project, it's only a small site and don't want to use the overhead and 'complexity' of smarty. I don't really like template systems that force you to make use of another language just to make it easier for designers (apparently).
像这样的事情 www.namepros/code/517342-php5-template -class.html 我正在看的是它,但是它更强大,更可靠.
Something like this www.namepros/code/517342-php5-template-class.html is what Im looking at but something which is a bit more robust and proven.
推荐答案PHP本身已经是模板引擎.那么,为什么不减少用模板引擎编写的模板引擎带来的开销,然后只使用PHP呢?
PHP by itself is already a template engine. So why not cut out the overhead a template engine written in a template engine brings with it and just use PHP then?
<h1><?php echo $pageTitle ?></h1> <div> <ul> <?php foreach($items as $item): ?> <li><?php echo htmlentities($item); ?></li> <?php endforeach; ?> </ul> </div>如果您需要其他功能,请考虑使用ViewHelper,例如封装诸如添加链接名称或翻译之类的东西的小型函数,例如
If you need added functionality, consider using ViewHelper, e.g. small functions that encapsulate stuff like adding links names or translating, e.g.
<table> <?php foreach($items as $key => $item): ?> <tr class="<?php echo oddEven($key)?>"> <td><?php echo productLink($item->id); ?></td> <td><?php echo translate($item->description); ?></td> </tr> <?php endforeach; ?> </table>如果太冗长,请查看 HEREDOC和NOWDOC语法,如果这仍然不是您想要的,这里是一些模板引擎的列表:
If that's too verbose, have a look at HEREDOC and NOWDOC syntax and if this is still not what you are looking for, here is a list of some template engines:
- www.webresourcesdepot/19-promising- php-template-engines/
- en.wikipedia/wiki/Web_template_system#Server-side_systems
- www.webresourcesdepot/19-promising-php-template-engines/
- en.wikipedia/wiki/Web_template_system#Server-side_systems
或者,如果您实验性的话,请查看XHP,这是Facebook对模板引擎的扩展方法:
Or, if you feel experimental, have a look at XHP, Facebook's extension approach to a Template engine:
- www.facebook/notes/facebook-engineering/xhp-a-new-way-to-write-php/294003943919
- toys.lerdorf /archives/54-A-quick-look-at-XHP.html
- github/hhvm/xhp-lib
- www.facebook/notes/facebook-engineering/xhp-a-new-way-to-write-php/294003943919
- toys.lerdorf/archives/54-A-quick-look-at-XHP.html
- github/hhvm/xhp-lib
更多推荐
基于PHP5的轻量级模板类/系统
发布评论