_ _ _____ _ _ _
| || |_ _ __ _ ___ |_ _|__ _ __ _ __| |__ _| |_(_)_ _ __ _
| __ | || / _` / _ \ | |/ -_) ' \| '_ \ / _` | _| | ' \/ _` |
|_||_|\_,_\__, \___/ |_|\___|_|_|_| .__/_\__,_|\__|_|_||_\__, |
|___/ |_| |___/
Creating templates for hugo is something that can be difficult to master, a such skills are often reserved for those individuals who work with javascript, Go Language, and Html on a permanent daily basis. But regardless of this limitation, with effort, one can expect to get by with their dabbling in the language.
As previously mentioned, Hugo uses a templating language which is a subset of the Go programming language. It’s sort of a markup language specific to go, but it does more than provide document styling. There is little else but a page which mentions text templating in the go manual. Which for the most part, has been copied here.
Here we have our quick reference of go template tags again:
- "." = Current Context
- "$." = refers to the current context in a range or code block.
- "|" = Is a pipe, and can be used to pipe values to functions or methods.
- "$" = Can be used to indicate a variable.
- ":=" = Is used to initialize a variable.
- "=" = Can be used to assign a variable a value.
- ".Page" = Refers to the given page.
- ".Site" = Refers to the site in it's entirety.
- ".Site.data" = Refers to the data folder of the site.
- "" = Is of course a comment.
- "" = Is a comment without whitespaces.
- '' = `Partial` is used to access the theme's partials
- '' = will give you access to a cached partial
- '' = will allow you to access hugo's built in tempaltes.
Because Go template language is more functional than a markup language, but not expansive enough to be it’s own programming language. A developer will run into situations where the usual method is nonexistent. We will call these hangups.
When Hugo begins to render content it determines where to begin looking for templates by five important factors:
From there almost all template lookup orders flow from high specificity to low specificity. Meaning Hugo will look for the most specific templates first, and will continue to look for templates that are gradually less and less specific until it reaches the least specific template location.
More specifics on this can be found in the Hugo Documentation
In order to configure Hugo to generate a “custom” type of file, you will need to configure a new custom output
format, but before you do that you need to settle on what mediatype this custom output will use. More than
likely, you will need to create a new custom mediatype as well. All of which can be done in the config.toml
or hugo.toml
file.
[mediaTypes]
[mediaTypes."text/redirects"]
suffixes = ["html"]
[outputFormats]
[outputFormats.Redirects]
name = "redirects"
baseName = ""
isPlainText = true
mediaType = "text/redirects"
permalinkable = false
In order to generate this custom output, you will need to place a template for it in the layouts/_defaults
folder.
Here is where I should provide some definition to what differentiates methods from functions. It would be nice if I understood this more thoroughly my self.