简体   繁体   English

为什么我们必须在服务器端使用诸如Jade,EJS和Hogan之类的View模板?

[英]Why do we have to use View Templates such as Jade, EJS and Hogan on server side??

I'm learning node.js thesedays and new to back-end. 这些天,我正在学习node.js,并且是后端的新手。 One thing that I'm confused is why do we have to use View Templates? 我很困惑的一件事是为什么我们必须使用视图模板? Why don't we just use HTML form on server side? 我们为什么不只在服务器端使用HTML表单?

Templates are used in most of the language platforms, not just NodeJS. 模板用于大多数语言平台,而不仅仅是NodeJS。 There is a school of thought in software development that says "Your data/business logic should be separate from your presentation" and templates are used to achieve that. 在软件开发中有一个流派,说“您的数据/业务逻辑应该与您的演示文稿分开”,并使用模板来实现这一目标。 This is ofcourse the right concern for software development and it's benefit are most visibly seen in Model-View-Controller frameworks like Rails, Laravel, and Symphony to name a few. 当然,这是对软件开发的正确考虑,它的好处在Rails,Laravel和Symphony之类的Model-View-Controller框架中最为明显。

There are many benefits to keeping your data/business logic separate from presentation: 将数据/业务逻辑与表示分离开来有很多好处:

  1. Developer and Designer roles are vastly separated and their responsibilities are well defined. 开发人员和设计人员的角色完全分开,并且职责明确。

  2. Your application user interface becomes modular that is it can be changed without involving a developer. 您的应用程序用户界面变成了模块化,可以在不涉及开发人员的情况下进行更改。

  3. Your application business logic can be altered by developers as long as they provide the data required for template rendering. 开发人员可以更改您的应用程序业务逻辑,只要他们提供模板呈现所需的数据即可。

  4. Code consistency is vastly improved as the templating language provides uniformity and you do not have to use dynamic language constructs with raw markup(in case of web projects but you get the idea). 由于模板语言提供了统一性,并且代码不必使用带有原始标记的动态语言结构(对于Web项目,但您可以理解),代码的一致性得到了极大的改善。

For a practical example of these benefits, you can look into many open source projects like Ghost, October CMS etc. 有关这些好处的实际示例,您可以研究许多开源项目,例如Ghost,October CMS等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM