php 是否有纯 html 模板系统?
我已经开始使用 clojure 进行编码,Enlive 给我留下了深刻的印象。我真正喜欢的一件事是 Enlive 使用纯 html 模板。所以模板就是一个包含 html 的文件,以 .html 结尾,就这么简单。它被解析为 dom 树,然后该 dom 树由 clojure/enlive 操作、组合、动态化等。html 模板文件中没有语法,完美干净的分离。
通过 JavaScript 完成的类似系统的另一个示例是 PURE。
php中有类似的东西吗? 或者,一般来说,有什么方法可以进行纯 html 模板化?
I have started coding in clojure, and I'm really impressed by Enlive. One thing that I really like about it is that Enlive uses html-only templates. So a template is a file with html in it, ending in .html, simple as that. It gets parsed into a dom tree and then that dom tree is manipulated by clojure/enlive, combined, made dynamic, etc. No syntax in the html template files, a beautifully clean separation.
Another example of a similar system, done via javascript, is PURE.
Is there anything like that in php?
Or, in general, any ways of doing html-only templating?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
很高兴听到 Enlive。我多年来一直在思考这个概念,并一起编写了 PHP 中的一些东西< /a> 共享一些原则:模板是纯 HTML,您可以通过使用 CSS 或 XPath 将内容寻址到文档中的特定节点来“填充”它们。
我还尝试将一些规定放在一起,将内容分离成某种“样式表”……好吧,“样式表”是错误的词。我将它们称为内容寻址表(该项目称为 CAST,即内容寻址样式模板)。 CAS 看起来就像您所期望的那样:
假定内容的值是 PHP 表达式。还有一些设置 PHP 的规定也适用于选择器。
运行 tarball 中的
cssfill.php
脚本(最好的调用可能是./cssfill.php pangolin.cas pangolin.html
,您可能需要更改cssfill.php 中 php 解释器的路径),查看输出,与输入文件进行比较。如果这篇文章激起了您对这个想法的热情,请随时告诉我。我一直想知道这是否是一个疯狂的想法,或者它是否有一席之地,如果确实如此,我很乐意将其变成一个经过深思熟虑发布的开源项目,而不是随机扔到互联网上的 tarball。
Fascinated to hear of Enlive. I've been thinking about this concept for a few years and have hacked together something in PHP that shares some principles: templates are pure HTML, and you "fill" them by addressing content to a specific node in the document using CSS or XPath.
I also experimented with throwing together some provisions for separating the content out into a "stylesheet" of sorts... well, "stylesheet" is the wrong word. I'm calling them content-addressing sheets (the project is called CAST, for content-addressed-style-templating). A CAS looks like you might expect:
The values of content are assumed to be PHP expressions. There's some provision for setting up PHP that applies across selectors, too.
Take a run of the
cssfill.php
script that's in the tarball (best invocation is probably./cssfill.php pangolin.cas pangolin.html
, you might have to change the path to your php interpreter inside cssfill.php), take a look at the output, compare with the input files.If this post generates any enthusiasm for the idea in you, feel free to let me know. I've been wondering whether this was a crazy idea or whether it has a place, if it does, I'd be happy to turn it into a thoughtfully released open source project as opposed to a tarball randomly tossed onto the internet.
您可以查看phptal.org。它是一个使用 HTML 标签的 PHP 模板引擎。
但它并没有那么快。
您还可以检查其他项目,例如twig-project.org,速度更快。
You can check phptal.org. It's a template engine for PHP that uses HTML tags.
But it's not that fast.
You can also check other projects like twig-project.org witch is waaay faster.
查看 PHPTAL。
PHPTAL 是 PHP5 的 XML/XHTML 模板库,提供编译模板和细粒度缓存。
模板是在纯 XML/HTML 标记中定义的。
Checkout PHPTAL.
PHPTAL is a XML/XHTML template library for PHP5 which provides compiled templates and fine-grained caching.
Templates are defined in pure XML/HTML markup.
有趣的开始。但令我印象深刻的是,为什么我们不能使用带有样本文本的不同模板来更改视图和元素的不同状态,并提取代码来创建现有模板系统或只是用内容填充它。发现工作流程感觉如此破碎和复杂 - 不喜欢将 html 与 php / js 混合,也不喜欢编写抽象模板系统。需要大量的大脑 - 大量的沟通,但没有简单的可视化。
Interesting starts. But I'm impressed why we can't have diferent template with specimen text to change the view and the different state of elements - and extract the code to create exiting template systems or just fill it up with content. Find the workflow feels so broken an complicate - don't like mixing html with php / js nor writing abstract template systems. Need to much brain - to much commication without easy visualisations.
我想呸! php 模板引擎正是您所寻找的,它使您的 html 模板保持完整,使您可以更好地重用您的 html。
完整源代码在这里 http://github.com/givanz/psttt
I think Psttt! templating engine for php is exactly what are you looking for, it keeps your html template intact allowing you to better reuse your htmls.
full source code here http://github.com/givanz/psttt