

TagsĪny text at the beginning of a line-by default-is interpreted as an HTML tag.

You can follow the Pug syntax examples in this section online, at the official web site's demo page ( ) or by writing standalone Node.js scripts (examples are presented in the section “Pug Standalone Usage,” which appears later in this chapter). Therefore, we need to be careful to follow the proper syntax. As with a real pugs, this Pug can either be cute and friendly or can chew your butt off if you don't know how to use it. Pug is a Node.js brother of Haml, in the sense that it uses whitespace and indentation as part of its language. No matter which approach we take, the syntax of the libraries themselves remains intact. REST API approaches), we can deduce that templates can be compiled into HTML either server-side (traditional approach) or client-side (REST API approach). If we go back to the diagrams in the previous chapter (traditional vs. In web apps, it's beneficial to use templates because we can generate an infinite number of pages dynamically with a single template! Another side benefit is when we need to change something we can do it in one place only. For those of you familiar with the model–view–controller concept, templates belong to the view. In the case of web applications, views are HTML pages (or parts of them), but they can be JSON or XML files, or GUIs in the case of desktop programs.

Chapter 4 Template Engines: Pug and HandlebarsĪ template engine is a library or a framework that uses some rules/languages to interpret data and render views.
