PHP 模板值得学习 Smarty 吗?
我正在使用类似 MVC 的架构构建一个简单的 10 页网站。 Smarty模板引擎值得学习吗?
I'm building a simple 10-page site using an MVC-like architecture. Is it worth learning the Smarty templating engine?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
模板引擎增加了开销。
仅当您需要让其他人创建/编辑模板并且您不希望他们能够使用 PHP 时,才应使用模板引擎。
如果您是唯一的维护者,请坚决选择纯 PHP。如果您的团队值得信赖(他们都是开发人员),请坚持使用纯 PHP。如果您的设计人员不了解 PHP,或者更重要的是,让他们使用 PHP 是危险的,那么请使用 Smarty 或其他模板引擎。
话虽这么说,您想知道是否应该学习 Smarty。如果使用 Smarty 创建模板,您需要学习 Smarty。如果您只是实现 Smarty 模板引擎,那么您实际上不需要学习 Smarty。
Template engines add overhead.
You should only use a template engine if you need to have others create/edit templates and you do not want them to be able to use PHP.
If you are the sole maintainer, defiantly go with plain PHP. If your team can be trusted (they are all devs), stick with plain PHP. If you have designers that don't know PHP or, more importantly, letting them use PHP is dangerous, then use Smarty or another template engine.
That being said, you are wondering if you should learn Smarty. You'll need to learn Smarty if creating templates with Smarty. You don't really need to learn Smarty if you are just implementing the Smarty template engine.
Smarty 是易于学习和使用的模板引擎,但我强烈建议学习和使用 Twig< /a> 相反。
Smarty is template engine easy to learn and use, but I strongly recommend learning and using Twig instead.
不需要。
一个 10 页的网站很容易建立。如果你想使用Smarty,一开始就得多花一点时间来学习~
no need.
a 10-page site is easy to build. if you would like to use Smarty, you will have to spend a little more time to learn it at the beginning~
PHP 本身就是一种不错的模板语言。除非需要高级功能,否则定制解决方案只会使听起来相当简单的设置变得复杂。
PHP is a decent templating language itself. Unless there is need for advanced features, custom solutions will only complicate what sounds like a fairly simple setup.
我从来没有抽出时间去研究 smarty。其他人吓跑了我,说它非常复杂。我现在做的几乎所有事情都使用 Twig ,甚至是小事情。即使对于一个小网站来说不值得,我认为从长远来看,它值得学习 - 在模板继承和块方面获得良好的基础是绝对值得的。
看看这个:
与
美味:
I never got around to looking into smarty. Others scared me away saying it was very complex. I use Twig for pretty much everything I do now, even small stuff. Even if it isn't worth it for a small site I think it's worth learning for the long term - getting a good grounding in template inheritance and blocks is absolutely worth it.
Check this out:
vs.
yummy:
我很久以前就用过Smarty,我建议你不需要那样使用模板引擎。 Smarty 减慢了整个系统的速度,因为它的核心源代码非常复杂,而且在某种程度上是不必要的。如果我对模板引擎有推荐,我会说:
1)使用一些基本的、轻型的模板引擎,例如XTemplate。我不确定它是否仍在开发中,但它确实很有用,所有内容都在一个类文件中,可供使用。语法也清晰明了。
2) 编写您自己的模板引擎,以便您可以自行定制最适合您当前系统的模板引擎。
但是,对于小型项目(少于 5-7 页),您可以控制所有内容,那么使用模板引擎可能是不必要的。
I used Smarty a long time ago, I would recommend you that it's no need to use Template Engine like that. Smarty slows down the whole system because its core source code is really complex, and somehow unnecessary. If I had a recommendation on Template Engine, I would say:
1) Use some basic and light Template Engine such as XTemplate. I'm not sure if it's still developing but it's really useful, everything is in one class file, ready to use. The syntax is also clear and sweet.
2) Write your own Template Engine, so that you can customize it on your own that best fits your current system.
But, however, for tiny and small project (less then 5-7 pages) in which you can have a control over everything, then using Template Engine is probably unnecessary.
当您动态生成 HTML 时,模板语言是一个不错的选择。无论是 Smarty 或其他东西(对于 PHP)、Razor 或 Forms(对于 ASP.NET),还是完全不同的东西(John Resig 的 客户端微模板框架)。
A templating language is a good choice when you're dynamically generating HTML. Be it Smarty or something else (for PHP), Razor or Forms (for ASP.NET), or something entirely different (John Resig's client-side micro-templating framework, perhaps).
我同意上面所说的。对于具有 10 个页面的简单网站,在 MVC 模型上使用 PHP 或使用轻量级快速模板引擎,例如 RainTPL 或Savant。
该测试可能存在偏见,因为它是由 RainTPL 作者发布的。但无论如何,我使用 Apache ab 实用程序对几个模板引擎进行了基准测试,并可以确认这些结果。 RainTPL 速度很快。
I agree with what is said above. For a simple site with 10 pages, use PHP on the MVC model or use a lightweight and fast template engine like RainTPL or Savant.
That test might be biased as it is published by the author of RainTPL. But anyway I benchmarked several template engines with the Apache ab utility and can confirm these results. RainTPL is fast.