基于PHP5的轻量级模板类/系统

编程入门 行业动态 更新时间:2024-10-26 06:37:16
本文介绍了基于PHP5的轻量级模板类/系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

考虑将模板系统用于新项目,它只是一个很小的站点,并且不想使用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的轻量级模板类/系统

本文发布于:2023-07-17 06:49:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130549.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   系统

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!