PLDB
Languages Features Calendar CSV Lists Blog About Donate Add Language
GitHub icon

Pug

< >

Pug is a template language created in 2010 by Tj Holowaychuk.

#114on PLDB 13Years Old 26.9kUsers
2Books 0Papers 12kRepos

Try now: Web · Riju

Pug – robust, elegant, feature rich template engine for Node.js


Example from Riju:
html body p Hello, world!
Example from hello-world:
doctype html html head title Hello World body h1 Hello World
Example from Linguist:
p. Hello, World!

Keywords in Pug

append block case default doctype each else extends for if in include mixin typeof unless var when

Language features

Feature Supported Token Example
Inheritance
Comments
// A comment
Line Comments //
// A comment
Strings
Assignment
- var title = "On Dogs: Man's Best Friend";

h1= title
Functions
mixin article(title)
  .article
    .article-wrapper
      h1= title
      if block
        block
      else
        p No content provided

+article('Hello world')

+article('Hello world')
  p This is my
  p Amazing article
Switch Statements
- var friends = 10
case friends
  when 0
    p you have no friends
  when 1
    p you have a friend
  default
    p you have #{friends} friends
Conditionals
- var user = {description: 'foo bar baz'}
- var authorised = false
#user
  if user.description
    h2.green Description
    p.description= user.description
  else if authorised
    h2.blue Description
    p.description.
      User has no description,
      why not add one...
  else
    h2.red Description
    p.description User has no description
File Imports
//- index.pug
doctype html
html
  include includes/head.pug
  body
    h1 My Site
    p Welcome to my super lame site.
    include includes/foot.pug
hasForEachLoops
ul
  each val in [1, 2, 3, 4, 5]
    li= val
Semantic Indentation

Books about Pug from ISBNdb

title authors year publisher
Programming Web Applications with Node, Express and Pug Krause, Jörg 2016 Apress
Programming Web Applications with Node, Express and Pug Jörg Krause 20161220 Springer Nature
haxe.html · pug.html · rexx.html

View source

PLDB - Build the next great programming language · v2023 · Day 153 · Docs · Build · Acknowledgements · Traffic Today · Traffic Trends · Mirrors · GitHub · feedback@pldb.com