

This simple command will create the corresponding HTML file next to the Pug one. Now that we have our index.pug template In order to compile it to HTML we need to open the terminal and navigate to the folder containing our file and run the command: html head title This is my first Pug file body header p My soon to be menu section p This is a post about Pug template engine, enjoy it! footer cool footer with lots of copyrights pug extension, you don’t need to type the angle brackets and because of the indentation you can also ignore the closing tags. As I mentioned earlier, Pug files use the. In this article I’ll show you the core features of Pug, to start let’s create our first file. Note: You need to have installed NodeJS in order to run npm commands from the terminal. Like most tools nowadays, Pug is a node package that can easily be installed on your system using the following npm command: Once you start using it, it’ll become an indispensable tool for you. When using modern CSS frameworks like Bootstrap and Foundation, most of the development becomes entirely about producing HTML, which brings out the power of Pug.
#PUG TEMPLATE EXAMPLES FREE#
It provides the ability to write dynamic and reusable HTML documents, its an open source HTML templating language for Node.js (server-side JavaScript), totally free to use and provides fast, easy, and fun HTML. Just like SASS, Pug is a prepocessor and, as such it helps you accomplishing tasks like wrapping away repetitive work by providing features not available in plain HTML. Simply put, Pug is a clean, white space/indentation sensitive syntax for writing html. Well with Pug, formerly known as “Jade” (a registered trademark, and as a result a rename was needed) it’s a high performance and feature-rich templating engine that’s easy to achieve.
#PUG TEMPLATE EXAMPLES HOW TO#
In this blog, we have learned how to use the templating engines and how we can install and integrate it in your node application.Clean and organize HTML, that’s what we as Front-end Developers always aim for. Now go to the browser and run the You will see the desired output Conclusion Save all the files and run the server using :- npm start This means that we are telling express that you want to compile dynamic content using pug as a templating engine and where to find these templates. Next step is to just add the pug file in the app.js file. P.firstParagraph This is the first template!!!

#PUG TEMPLATE EXAMPLES CODE#
Pug template exampleĪdd the code in the body section h1#myHeading Pug template For getting the HTML template in your pug file, just simply write html in the code section you will get the pug structure of the html template. npm install pugĪfter installing, create the index.pug file inside the views folder having the ‘.pug’ as an extension. Install PUG as a dependency in our Node application. But ‘if’ statements, ‘iterations’ will be included in this. It use minimimal html and custom template language which is extensible but generally offers only a set of things of operations you can do. Pug simplifies the creation of reusable HTML as well as the rendering of data from a database or API. It features a simpler syntax and compiles to HTML, allowing you to be more productive and your code to be more readable. Pug is a Node and browser-based template engine. And all the dependencies will get install in this file only.įor installing express, use npm install nodejs expressįor installing nodemon, use npm install nodemon What is pug? Here we begin!!! Setting up Nodejsįor using the templating engine we need the node to be installed in our system and then create the package.json file in your project with the help of following command : npm initĪfter running this command, you will see the package.json file in your folder. And how we can hold the dynamic content in our HTML pages using the templating engine. In this blog, we will look how we can use pug as a templating engine for building our node application.
