模板引擎解决了什么?
PHP模板引擎解决了将数据与模板的分离,也就是说将模板文件和数据通过模板引擎生成最终的HTML代码,也是前后端分离的一种方式。
smarty
smarty是一个基于PHP开发的PHP模板引擎。它提供了逻辑与外在内容的分离,简单的讲,目的就是要使用PHP程序员同美工分离,使用的程序员改变程序的逻辑内容不会影响到美工的页面设计,美工重新修改页面不会影响到程序的程序逻辑,这在多人合作的项目中显的尤为重要。
官方网站: https://www.smarty.net
中文手册: https://www.smarty.net/docs/zh_CN/
Template Lite
Template Lite是一个非常快而且很小HTML模板引擎。该引擎支持Smarty模板引擎所具有的大部分功能和过滤器。
官方网站: http://templatelite.sourceforge.net
源码: https://sourceforge.net/projects/templatelite/files/
文档: http://templatelite.sourceforge.net/docs/index.html
mustache
支持多语言的模板引擎,基本上常用的编程语言均支持,如php、java、js、python、ruby等。
官方网站: http://mustache.github.io
源码: https://github.com/bobthecow/mustache.php
文档: http://mustache.github.io/mustache.5.html
Twig
Twig是一款灵活、快速、安全的PHP模板语言。
官方网站: https://twig.symfony.com
安装: composer require "twig/twig:^2.0"
Blade
Blade 是 Laravel 提供的一个非常简单但很强大的模板引擎,不同于其他流行的 PHP 模板引擎,Blade 在视图中并不约束你使用 PHP 原生代码,所有的 Blade 模板后缀名都要命名为 .blade.php。
官方网站: https://laravel.com
文档: https://docs.golaravel.com/docs/5.0/templates/
源码: https://github.com/illuminate/view
phptpl
轻量级模板引擎,2种php模板思想,SimpleTpl.php是基于正则替换模板中注释标签(替换前置条件是模板文件的修改时间戳晚于生成后的文件时间戳,或者生成后的文件不存在), PhpTpl.php基于php的extract()函数思想编写的模板引擎。
官方网站: http://www.nfangbian.com
源码: https://github.com/jellycheng/phptpl
FastTemplate
一个文件class.FastTemplate.php3,一个简单的变量插值模板类,它分析你的模板,把变量的值从HTML代码中分离处理,很老的模板引擎,网上代码都很难找到。
源码: https://github.com/onehost1/Fasttemplate
文档:http://www.devshed.com/c/a/php/php-fast-template/
phplib Template
比较老牌的模板引擎。
官方网站: http://phplib.netuse.de
think-template
从ThinkPHP5.1独立出来的编译型模板引擎。
源码: https://github.com/top-think/think-template
latte
Latte is a template engine for PHP which eases your work and ensures the output is protected against vulnerabilities, such as XSS。
官网: https://latte.nette.org
安装: composer require latte/latte
FOIL
PHP template engine, for PHP templates.一个原生PHP模板库
官网: https://foilphp.github.io/Foil/
phptal
一个TAL模板语言的PHP实现。
官网:https://phptal.org
platesphp
一个原生PHP模板库。
官网:http://platesphp.com
jade模板
A complete and fully-functional implementation of the Jade template language for PHP。
官网:http://jade.talesoft.codes
安装: composer require "talesoft/tale-jade:*"
模板引擎分类,如下:
* 前端模板引擎: 主要是js模板引擎,如artTemplate、mustache、xtemplate、BaiduTemplate等 * 后端模板引擎:php模板引擎、java模板引擎、nodejs模板引擎 * 前后端通用模板引擎:如mustache
http://mustache.github.io
https://github.com/arnaud-lb/MtHaml
https://github.com/pyrocms/lex
比较大型的php框架,基本上自带自己的模板引擎,如laravel框架,thinkphp框架,ci框架,yii框架,phalcon等