有没有像 Twig 这样使用 PHP 语法的模板系统?
我想使用像 Twig 这样的模板系统(特别是块功能),但使用纯 PHP。
例如,我发现 http://phpsavant.com/docs/ 但似乎不支持块或类似的东西。
编辑 我发现一些似乎具有常规 PHP 代码的块语法: http://phpti.com/
I would like to use a template system like Twig (specifically the block functionality) but in plain PHP.
For example, I found http://phpsavant.com/docs/ but it seems that doesn't support blocks or anything similar.
Edit
I found something that appears to have block syntax with regular PHP code: http://phpti.com/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您正在寻找的模板语言称为 PHP!
The templating language you are looking for is called PHP!
Laravel 框架中包含一个名为 Blade 。
您可以将普通的旧 PHP 与 Blade 模板语法混合使用,其中
{{...}}
也可转换为或
>
也有你在 Twig 中知道的块,但它们被称为
节
。这是在
Illuminate\View
命名空间下 - 参见在 GitHub 上,并且可以使用 Composer 下载,因为它也在 Packagist 上注册 -就在下面给你的项目的composer.json。我目前不确定您将如何尝试从自定义项目渲染模板。如果我发现了,我会更新我的答案。
There is one included in the Laravel framework called Blade.
You can mix plain old PHP with the Blade templating syntax, where
{{...}}
also translates to<?=...?>
or<?php echo ... ?>
Also has blocks you know in Twig, but they are called
sections
.This is under the
Illuminate\View
namespace - See on GitHub, and can be downloaded with Composer as it is also registered on Packagist - just at the following to your project's composer.json.I'm not certain at this point about how you'd attempt to render a template from a custom project. If I find out, I'll update my answer.
Symfony(默认使用 Twig)也有一个基于 php 的模板系统,其工作方式与 Twig 非常相似。它具有模板继承并使用“槽”,相当于 Twig 的块。它是一个独立的库,可以在完整的 Symfony 框架之外使用。
http://symfony.com/doc/2.0/cookbook/templated/PHP.html
Symfony (which uses Twig by default) also has a php-based template system that works very much like Twig. It has template inheritance and uses 'slots', which are equivalent to Twig's blocks. It's a stand-alone library that can be used outside of the full Symfony framework.
http://symfony.com/doc/2.0/cookbook/templating/PHP.html
PHP 是一种模板语言(是的),块可以用缓冲区来实现:
然后在主布局中回显块的内容:
事实上,这就是大多数模板引擎正在使用的。
使用模板库有巨大的优势(缓存、默认转义等......)
PHP is a templating language(yes it is) , blocks can be implemented with buffers :
then in the main layout echo the content of the blocks :
in fact that is what most template engines are using.
using template libs have huge advantages though ( caching , escaping by default ,etc ... )
据我了解,在 Laravel 中,对视图使用
Blade
是可选的。您可以使用像view.php
这样的文件名来代替view.blade.php
并在那里使用普通的旧 PHP 语法。唯一的问题是你不能同时拥有view.php
和view.blade.php
因为它们都会响应As far as I understand use off
Blade
for views is optional inLaravel
. You can use file name likeview.php
instead ofview.blade.php
and use plain old PHP syntax there. Only catch is you cannot have bothview.php
andview.blade.php
as they both respond to