为什么要在模板框架中使用模板引擎? [英] Why use a templating engine with a framework?
问题描述
我最近发现了PHP框架 Kohana (很棒),并且正在阅读有关在其中使用它的线程.与诸如 Smarty 或树枝.我的问题是为什么要打扰?按照定义,MVC框架肯定是一个模板引擎.甚至可以说,原始" PHP都是模板引擎.在像Kohana这样的框架中已经存在的内容之上添加另一种抽象级别有什么可能的好处?
I recently discovered the PHP framework Kohana (which is awesome) and was reading a thread about using it in conjunction with a templating engine such as Smarty or Twig. My question is why bother? Surely an MVC framework, by definition, is a templating engine. Even "raw" PHP is, arguably, a templating engine. What possible benefits are there of adding another level of abstraction on top of what's already present in a framework such as Kohana?
编辑- 我意识到MVC框架与模板引擎不是同一回事,但可以肯定的是,V部分会完成相同的工作吗?也许用一种更好的措辞方式是;为什么在MVC框架的V部分顶部添加模板引擎?
EDIT - I realise that an MVC framework isn't the same thing as a templating engine, but surely the V part does the same job? Perhaps a better way of phrasing things would be; why add an templating engine on top of the V part of an MVC framework?
推荐答案
我有两个非常好的理由可以考虑...
I have two really good reasons I can think of for doing this...
- 创建以一致的格式在整个网站中重复的标记更加容易,而且您以后可以进行更新而无需花费很多精力.
- 如果这是一家真正的公司,那么确定内容的人不太可能真正熟悉HTML,更不用说PHP.拥有一种简单的模板语言,可以使样式保持正确的方式,并在无需太多代码知识的情况下即可生成有效的标记.
这篇关于为什么要在模板框架中使用模板引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!