有没有一个html模板系统的php? [英] Is there a html-only templates system for php?

查看:152
本文介绍了有没有一个html模板系统的php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在clojure中编码,我对 Enlive印象深刻。 。我真的很喜欢它的一件事是Enlive使用仅html模板。所以一个模板是一个带有html的文件,以.html结尾,很简单。它被解析成一个dom树,然后dom树被clojure / enlive,组合,动态等操作。在html模板文件中没有语法,一个美观的分离。



通过javascript完成的类似系统的另一个示例是 PURE



在php中有什么东西吗?
或者,一般来说,只有html模板的任何方式?

解决方案

我一直在思考这个概念几年,并一起黑客入侵在PHP 共享一些原则:模板是纯HTML,并且通过使用CSS或XPath将内容寻址到文档中的特定节点来填充它们。

  $ t = new Template('yourfile.html'); 
$ t-> fill('#nav',$ someMarkup);
$ t-> fill('#header',$ otherMarkup);

我还试验了一些将内容分成样式表的规定。好了,stylesheet是错误的词。我称它们为内容寻址表(该项目称为CAST,用于内容寻址样式模板)。 CAS看起来像你可能期望的:

  .col #foot {
content:'foot'
}

#content {
content:file_get_contents('pangolin.txt');
}

内容的值假定为PHP表达式。有一些规定设置PHP也适用于选择器。



运行tarball中的 cssfill.php 脚本(最好的调用大概是 ./ cssfill.php pangolin.cas pangolin.html ,你可能需要改变你的php解释器的路径cssfill.php),看看输出,与输入文件比较



如果这篇文章对你的想法产生了任何热情,请随时让我知道。我一直在想,这是一个疯狂的想法,或者它是否有一个地方,如果它是,我会很乐意把它变成一个周密释放的开源项目,而不是一个tarball随机扔到互联网上。 p>

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?

解决方案

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.

$t = new Template('yourfile.html');
$t->fill('#nav',$someMarkup);
$t->fill('#header',$otherMarkup);

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:

.col #foot {
    content: 'foot';
}

#content {
    content: file_get_contents('pangolin.txt');
}

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.

这篇关于有没有一个html模板系统的php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆