SitePoint
  • Blog
  • Forum
  • Library
  • Login
Join Premium
  1. Details
  2. Creator
  3. Content
  4. Reviews
  5. FAQ
A Beginner’s Guide to Pug Cover

A Beginner’s Guide to Pug

4

average rating (1 votes)

Created by

James Hibbard

Published by

SitePoint

Last Updated

1 April 2019

Details

In this guide, we’ll demonstrate how to get up and running with Pug, a template engine for Node and for the browser. We’ll start by installing it, go over its basic syntax and then look at several examples of using JavaScript in Pug. Finally, we’ll explore a couple of Pug’s more advanced features.

Description

As web designers or developers, we likely all have to write our fair share of HTML. And while this is not the most difficult task, it can often feel a little boring or repetitive. HTML is also static, which means that if you want to display dynamic data (fetched from an API, for example), you invariably end up with a mishmash of HTML stings inside JavaScript. This can be a nightmare to debug and to maintain.

This is where Pug comes in. Pug is a template engine for Node and for the browser. It compiles to HTML and has a simplified syntax, which can make you more productive and your code more readable. Pug makes it easy both to write reusable HTML, as well as to render data pulled from a database or API.

In this guide, I’ll demonstrate how to get up and running with Pug. We’ll start by installing it from npm, go over its basic syntax and then look at several examples of using JavaScript in Pug. Finally, we’ll explore a couple of Pug’s more advanced features by building a simple Node/Express project which uses Pug as its template engine.

Creator

James Hibbard avatar

James Hibbard

James is a regular contributor to SitePoint, most notably on topics around JavaScript. He's also the technical editor for various books (e.g. JavaScript: _Novice to Ninja_ and _Jump Start Vue.js_). He also works for his local university as a network admin / web dev where he spends a fair bit of my time working on Rails apps.
James Hibbard avatar

Content

1
Preview
2
3

Reviews

Profile
Michael

Well written. I was looking more for a reference guide where this was more for a person that had never heard of PUG.

Frequently Asked Questions

A Beginner’s Guide to Pug Cover

A Beginner’s Guide to Pug

4

  • Unlimited access to this title and 600+ others in our library

  • New titles added frequently

  • Cancel anytime

Stuff we do

  • Premium
  • Newsletters
  • Forums

About

  • Our Story
  • Terms of use
  • Privacy Policy
  • Corporate Memberships

Contact

  • Contact us
  • FAQ
  • Publish your book with us
  • Write an article for us
  • Advertise

Connect

© 2000 – 2024 SitePoint Pty. Ltd.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.