官术网_书友最值得收藏!

So, what is Handlebars?

To answer this properly, we need to first understand what a templating engine is, or better, what it comes to accomplish. Any dynamic site (blog, store, and so on) has parts which remain static, and at least rules on how the dynamic data should be inserted. A templating engine can and should be thought of as a new language in its own right and has a specialized syntax made specifically for rendering views.

Before templating engines you would have some kind of code in your actual DOM pages, through which you would insert the dynamic pieces of data at specific points. This is not great code separation, and it's definitely not a very clean option. A templating engine is meant to augment this step with its specialized syntax made specifically for this purpose; if done right, you should end up with clean and reusable templates, and leave your app clear of any bodge code.

Mustache was a pretty popular templating library for years and has basically been ported to nearly every programming language available. The problem with Mustache is that it is fairly opinionated on how you should write your templates; it follows a strict "View-Controller" separation and is a purely logic-less engine made specifically for replacing expressions with pre-computed data. Handlebars is a superset of the Mustache library, that adds a lot of logic and extensibility, making it a more flexible solution, while still retaining full backward compatibility, so that any Mustache templates can work out of the box. Following are the features of Handlebars:

  • It has a very simple and easy to write syntax
  • It allows you to add some logic using helpers but still separates it from the actual template's code to keep them easy to manage
  • It's very fast and allows you to pre-compile your templates in JavaScript

Because of this, Handlebars has become the premier choice when it comes to frontend templates and is currently being used in many of the popular frameworks such as Meteor and Ember.js.

Not to mention the fact that it was built by the legendary Yehuda Katz, who is a core member on projects such as, jQuery, Ruby on Rails, and the Ember.js framework.

主站蜘蛛池模板: 达孜县| 枣庄市| 呼和浩特市| 西安市| 安庆市| 惠来县| 莱芜市| 库尔勒市| 永靖县| 淳安县| 新郑市| 通河县| 株洲市| 广州市| 桃江县| 临清市| 安福县| 兰西县| 东丽区| 中西区| 兰西县| 体育| 临潭县| 鹰潭市| 涞源县| 盐边县| 泽普县| 东山县| 南江县| 阜新市| 南开区| 茂名市| 道真| 泰和县| 龙州县| 西吉县| 凤阳县| 辰溪县| 黑水县| 会宁县| 建宁县|