Smarty 的替代方案可将 php 中的演示文稿与代码分离?
我目前正在为我们的生产站点使用 Smarty 模板系统,但我很好奇使用此模板引擎对我的性能造成了多大影响。有更快的替代方案吗?有没有一种方法可以让我不必使用这样的模板系统?谢谢你!
I'm currently using the Smarty templating system for our production site, but am curious how much of a performance hit I'm taking by using this templating engine. Are there faster alternatives? Is there a way to code so I may not have to use such a templating system? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您还可以使用 XSL 转换将逻辑与表示分离。 XSLT 转换器接收 XML 树并生成 HTML 输出,使用 XSLT 转换来生成演示文稿。
但XSLT学习起来比较困难,需要XML和XPath的知识。我在最近的项目中一直在使用 Smarty,但我当前的项目是基于 XSLT 模板构建的,所以我必须学习 XSLT。对我来说,Smarty 及其祖先 FastTemplate 似乎更复杂。然而,XSLT 是另一种将逻辑与表示分离的方法。
XML 和 XML 的优势XSLT 的优点是这些技术可以与不同的语言一起使用,而不仅仅是与 PHP 一起使用。
除此之外,还有一个模板引擎 - PHP 模板引擎。它是 Drupal CMS 的默认模板引擎。我不是 Drupal 专家,所以我对此无话可说。不过它使用PHP语法,所以学习起来相当简单。
您可以此处了解有关 XSLT 的信息。
希望我的回答对您有用。
Also you can use XSL transformations to separate logic from presentation. XSLT-transformer receives XML tree and generates HTML output, using XSLT transformations to produce presentation.
But XSLT is quite difficult for studying and demands knowledge of XML and XPath. I have been using Smarty in my recent projects, but my current project is build on XSLT templates, so I had to learn XSLT. It seems more complicated to me, that Smarty and its ancestor FastTemplate. However, XSLT is another way to separate logic from presenatation.
Advantage of XML & XSLT is that these technologies are used with different languages, not only with PHP.
Besides there is one more template engine - PHP template engine. It is default template engine for Drupal CMS. I'm not Drupal expert, so I can say nothing about it. However it uses PHP syntax, so it is quite simple to learn.
You can read about XSLT here.
I hope my answer will be useful for you.
你可以试试Psttt! php 模板引擎
完整源代码在这里 http://github.com/givanz/psttt
You can try Psttt! templating engine for php
full source code here http://github.com/givanz/psttt
您不需要外部模板引擎来将代码与表示分离,您只需要逻辑即可。 PHP 本身作为模板引擎非常好——只是不要混合 PHP 代码和 HTML。对于非程序员网页设计师来说,模板引擎更容易学习。
You don't need an external templating engine to separate code from presentation, you just need logic for that. PHP itself is perfectly fine as a template engine -- just don't mix PHP code and HTML. Template engines are just easier to learn for a non programmer web designer.
显而易见的答案 - 只需使用 PHP。许多人认为它是一种模板语言,尽管我更喜欢使用 Smarty。
Smarty 迫使 PHP 开发人员将业务逻辑、数据库调用等与表示分离。然而,训练有素的 PHP 开发人员可以使用 PHP 作为模板语言,并将演示文稿分开。
The obvious answer - just use PHP. Many argue that it IS a templating language, although I prefer to use Smarty.
Smarty forces PHP developers to separate business logic, database calls, etc from the presentation. However, a disciplined PHP developer can use PHP as a templating language and keep the presentation separate.