Hugo

Table of Contents

Overview

Reference

Front Matter

Shortcodes

Templating

Syntax

Hugo uses Go’s html/template and text/template libraries as the basis for the templating.

{{ . }} stands for the context variable. {{ $. }} stands for the global context variable.

// Front matter
{{ .Title }}      // built-in
{{ .Params.foo }} // user defined

// Site configuration
{{ .Site.bar }}
// Methods and Fields are Accessed via dot Notation
{{ .Params.bar }}


//Parentheses Can be Used to Group Items Together
{{ if or (isset .Params "alt") (isset .Params "caption") }} Caption {{ end }}


// Variables
{{ $address := "123 Main St."}}
{{ $address }}


// Includes
{{ template "partials/header.html" . }}
{{ partial "header.html" . }}


// Range
{{ range array }}
    {{ . }}
{{ end }}

{{range $element := array}}
    {{ $element }}
{{ end }}

{{range $index, $element := array}}
   {{ $index }}
   {{ $element }}
{{ end }}


// Conditionals
{{ if isset .Params "alt" }}
    {{ index .Params "alt" }}
{{else}}
    {{ index .Params "caption" }}
{{ end }}


// With (changes the context '{{ . }}')
{{ with .Params.title }}<h4>{{ . }}</h4>{{ end }}

Functions

Variables

Terminology

Topics

Directory Structure

.
├── archetypes
├── config.toml
├── content
├── data
├── layouts
├── static
│   ├─ css
│   ├─ js
│   └─ img
└── themes
archetypes
Templetes for new content files
config.toml
All Variables, TOML
content
Each top-level folder in Hugo is considered a content section.
data
Configuration files
layouts
Templetes in the form of .html
static
Static content like images, CSS, Javascript, etc.

Themes

/themes/<THEME>/static/js/jquery.min.js

When you want to customize the file above which is provided by the theme, you can override it with:

/static/js/jquery.min.js

Path

Taxonomies

Actor                    <- Taxonomy
    Bruce Willis         <- Term
        The Sixth Sense  <- Value
        Unbreakable      <- Value
        Moonrise Kingdom <- Value
    Samuel L. Jackson    <- Term
        Unbreakable      <- Value
        The Avengers     <- Value
        xXx              <- Value

Define taxonomies in config.toml as singular_key = "plural_value" form:

[taxonomies]
  tag = "tags"
  category = "categories"
  series = "series"

Add taxonomies to content with front matter:

+++
title = "Hugo: A fast and flexible static site generator"
tags = [ "Development", "Go", "fast", "Blogging" ]
categories = [ "Development" ]
series = [ "Go Web Dev" ]
slug = "hugo"
project_url = "https://github.com/gohugoio/hugo"
+++

How-to

Links