是否有更多不显眼的服务器端脚本(例如 hQuery)可以更轻松地进行模板化?
我遇到了这个有趣的模板工具,作者称之为 hQuery,它是一个“不显眼的服务器端脚本”。 [更多信息请点击这里 - https://github.com/choonkeat/hquery ]。它是用 Ruby 为 RoR 平台构建的。
我想知道类似的东西是否可用于其他平台(PHP、Python、Java)
PS:我知道像 smarty 和 twig 这样的模板引擎。我正在寻找更接近 hQuery 的东西。
I came across this interesting templating tool, what the author calls as hQuery which is an 'Unobtrusive Server-side Scripting'. [More information here - https://github.com/choonkeat/hquery ]. It is built in Ruby for the RoR platform.
I wanted to know if something similar is available for other platforms (PHP, Python, Java)
PS : I know about templating engines like smarty and twig. I'm looking for something closer to hQuery.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,我一直在做类似概念的事情,尽管更简单,在 PHP 中使用 phpQyery 和一些自定义的类似 html 的标记。
例如,这里是一个简化的非标准 html 块:
使用 phpQuery,它在服务器端与 XML 和 HTML Dom 节点一起工作,以一种与 jQuery 非常相似的方式,我使用来自数据库的内容映射所有标签,使用它们的 ID作为关键。以及所有带有函数自定义输出的
标记。因此
的存在会导致调用名为 component_logo 的函数,使用:并且
尽管它不是基于 MVC 模式并使用直接的过程编程,到目前为止,这种方法已经允许非常快速地开发中小型站点,同时保持事物的干燥。
Not that I know of, but I have been doing something similar in concept, although a lot more simple, in PHP using phpQyery and some custom html-like markup.
For instance, here is a simplified non-standard html chunk:
Using phpQuery, which works server-side with XML and HTML Dom Nodes, in a way very similar to jQuery, I map all tags with content coming from the db, using their ID as key. as well as all
<component></component>
tags with custom output from functions. So the existence of a<component id="logo"></component>
would cause the call of a function called component_logo, using:and
Although it's not based on a MVC pattern and uses straight procedural programming, so far this method has allowed for a very quick development of small to medium sized sites, while keeping things nicely DRY.
我不太喜欢使用其他模板引擎,真的是因为我发现它们对于我真正想做的任何事情来说都有点重量级(例如聪明)。
有一种观点会说:PHP 已经是一个模板引擎了……为什么要在模板中构建模板?
我确实在某种程度上不同意这一点,我发现模板在从 PHP 代码中抽象 HTML 方面非常有用。
下面是我使用的模板类中经过编辑的方法,它将解释实际制作它是多么容易。
这方面还有很多内容,但这是核心代码。将文件读入数组,内爆,搜索 $params 数组并将 $field 替换为 $html 中的 $value 。输出编辑后的$html。
您的 index.html 文件将类似于:
您的输出将是:
也许看看实现您自己的模板引擎! :)
I don't like using other templating engines much, really because I find them a little to heavyweight for anything I actually want to do (smarty for example).
There is a school of thinking that would say: PHP is already a templating engine... why build templates within templates?
I do disagree with this to an extent, I find templating very useful in abstracting HTML from PHP code.
Below is an edited method from my templating class that I use that will explain how easy it is to actually make yourself.
There is quite a bit more meat around this, but this is the core code. Read a file into an array, implode, search through the $params array and replace $field with $value in $html. Output the edited $html.
your index.html file will look something like:
Your output will be:
Maybe look at implementing your own templating engine! :)