

Example pug template code#
You’ll see that the code is a bit verbose, especially because we’re trying to emulate the exact same design as Bootstrap’s, which uses a lot of CSS classes. Place the following code there: mixin thumbCard(user) Before proceeding to the code, take a look at a Random User API output so you can see the JSON we’ll be handling in this mixin. Here, we’ll use them to iterate over the users and mount each of the user’s cards. They’re very useful in template list elements, like ul and ol or tables. They’re basically external JavaScript functions that can take arguments as params and be reused anywhere in your Pug files. Pug mixins allow you to create reusable blocks of Pug. The mixins folder is interesting because it stores Pug mixins. You can include images, HTML files, and any other type of file you want. However, Pugs aren’t the only ones who can do this. The includes folder will be useful when we need to break down the pieces of our final page into “includables”. pug extension, will have this icon properly identifying it. After you’ve successfully installed the Pug beautify plugin, each Pug file, which also ends in. The views folder is where everything related to Pug is going to be placed.

This is how it should look: Project file and folders. Discover popular ORMs used in the TypeScript landscape.Explore Tauri, a new framework for building binaries.
Example pug template how to#
Example pug template free#
The data will be fetched from the Random User Generation API, a free API for generating random user data. We’re going to recreate the same structure and design, but in Pug only. The design was taken from one of the official Bootstrap’s examples (an Album example). The goal is, by the end of the article, to have the following: Final example. To infer style, let’s give it up to the power of Bootstrap.

Instead, we’ll see how it works in practice by creating our own template from scratch. We’re not going to focus on its options, settings, and properties: for this, we already have the official docs, which are great. In this article, we’ll show you how Pug works. If you’re familiar with Node.js, it’s a piece of cake. It’s simple, fast, and flexible with an easy syntax that simplifies not only the creation but also the reuse of HTML code. But there are ports for other languages like Java, Python, Ruby, etc. Pug is a high-performance template engine heavily influenced by HTML and implemented with JavaScript for Node.js and browsers. With Pug, it’s a lot easier to reuse page pieces. In many cases, the use of a server side mechanism is necessary. HTML is just about static content made dynamic with many different tools and frameworks.Įven for static web sites, it’s tough to reuse page pieces that would be the same all over the website. The time has arrived to create templates for our web pages.
