Menu

gitpiper

Pug Cheat Sheet in April 2024

Last Updated: 10 April 2024

README.md

Pug

{: .-three-column}

Basic document

{: .-prime}

doctype html
html(lang='en')
  h1.class#id(name='hi')
    | This is some text, hello there,
    = name

  - javascript()

Elements

div
  | Just a div
.search
  | A div, with class 'search'
h1 A heading with text
h1= page.title
div.class
div.class1.class2
h1.header

Attributes

input(type='text' name='q' autofocus)
- var authenticated = true
body(class=authenticated ? 'authed' : 'anon')

See: Attributes

Comments

// This comment will appear in the HTML
//- This is a silent comment
//-
  Nesting inside a comment creates
  a comment block

See: Comments

Iteration

ul
  each user in users
    li= user

Layouts

//- page.pug
extends layout.pug

block title
  | hello

block content
  | hello
//- layout.pug
title
  block title
body
  block content

Includes (partials)

include ./includes/head.pug
include:markdown article.md

See: Includes

Multiline text

p.
  This is text that doesn't need to
  be prefixed by pipes.

{: data-line=“1”}

script.
  // It's great for raw
  // JavaScript and stuff
  alert('hello')

{: data-line=“1”}

Conditionals

if authenticated
  a(href='/logout') Sign out
else
  a(href='/login') Sign in

{: data-line=“1,3”}

See: Conditionals

Mixins

{: .-three-column}

Mixins

mixin list
  ul
    ···

{: data-line=“1”}

+list

Mixins allow you to create reusable code blocks.
See: Mixins

Mixin attributes

mixin pet(name)
  span.pet= name

{: data-line=“1”}

+pet('cat')

See: Mixin attributes

Mixin blocks

mixin article(title)
  article
    h2.title= title
    block

{: data-line=“1,4”}

+article('hello there')
  p Content goes here

See: Mixin blocks


338+ more cheat sheets for you in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️