diff --git a/content/en/functions/after.md b/content/en/functions/after.md index df2142ab6..9a2a68c5f 100644 --- a/content/en/functions/after.md +++ b/content/en/functions/after.md @@ -19,7 +19,7 @@ aliases: [] The following shows `after` being used in conjunction with the [`slice` function][slice]: -``` +```go-html-template {{ $data := slice "one" "two" "three" "four" }} {{ range after 2 $data }} {{ . }} diff --git a/content/en/functions/apply.md b/content/en/functions/apply.md index 4c36cf17e..0f02c1b4c 100644 --- a/content/en/functions/apply.md +++ b/content/en/functions/apply.md @@ -37,7 +37,7 @@ names: [ "Derek Perkins", "Joe Bergevin", "Tanner Linsley" ] You can then use `apply` as follows: -``` +```go-html-template {{ apply .Params.names "urlize" "." }} ``` @@ -49,7 +49,7 @@ Which will result in the following: This is *roughly* equivalent to using the following with [range]: -``` +```go-html-template {{ range .Params.names }}{{ . | urlize }}{{ end }} ``` @@ -83,7 +83,7 @@ This works, but the complexity of `post-tag-list.html` is fairly high. The Hugo This first version of `layouts/partials/post-tag-list.html` separates all of the operations for ease of reading. The combined and DRYer version is shown next: -``` +```go-html-template {{ with .Params.tags }}
Tags: diff --git a/content/en/functions/base64.md b/content/en/functions/base64.md index fb9ec9997..2568c1f47 100644 --- a/content/en/functions/base64.md +++ b/content/en/functions/base64.md @@ -42,7 +42,7 @@ You can also pass other data types as arguments to the template function which t Using base64 to decode and encode becomes really powerful if we have to handle responses from APIs. -``` +```go-html-template {{ $resp := getJSON "https://api.github.com/repos/gohugoio/hugo/readme" }} {{ $resp.content | base64Decode | markdownify }} ``` diff --git a/content/en/functions/chomp.md b/content/en/functions/chomp.md index 9bdb1be8a..eb44f726c 100644 --- a/content/en/functions/chomp.md +++ b/content/en/functions/chomp.md @@ -21,6 +21,6 @@ deprecated: false Useful in a pipeline to remove newlines added by other processing (e.g., [`markdownify`](/functions/markdownify/)). -``` +```go-html-template {{ chomp "

Blockhead

\n"}} → "

Blockhead

" ``` diff --git a/content/en/functions/cond.md b/content/en/functions/cond.md index 30b853251..b7b5e3d55 100644 --- a/content/en/functions/cond.md +++ b/content/en/functions/cond.md @@ -17,7 +17,7 @@ draft: false Example: -``` +```go-html-template {{ cond (eq (len $geese) 1) "goose" "geese" }} ``` diff --git a/content/en/functions/countrunes.md b/content/en/functions/countrunes.md index 01ded4d6f..e3add0d7f 100644 --- a/content/en/functions/countrunes.md +++ b/content/en/functions/countrunes.md @@ -20,7 +20,7 @@ deprecated: false In contrast with `countwords` function, which counts every word in a string, the `countrunes` function determines the number of runes in the content and excludes any whitespace. This has specific utility if you are dealing with CJK-like languages. -``` +```go-html-template {{ "Hello, 世界" | countrunes }} ``` diff --git a/content/en/functions/countwords.md b/content/en/functions/countwords.md index 17f0fa5c2..c0ca72aa3 100644 --- a/content/en/functions/countwords.md +++ b/content/en/functions/countwords.md @@ -18,7 +18,7 @@ deprecated: false The template function works similar to the [.WordCount page variable][pagevars]. -``` +```go-html-template {{ "Hugo is a static site generator." | countwords }} ``` diff --git a/content/en/functions/default.md b/content/en/functions/default.md index defdad480..b187331de 100644 --- a/content/en/functions/default.md +++ b/content/en/functions/default.md @@ -42,7 +42,7 @@ newparam: `default` can be written in more than one way: -``` +```go-html-template {{ index .Params "font" | default "Roboto" }} {{ default "Roboto" (index .Params "font") }} ``` @@ -58,7 +58,7 @@ A `default` value, however, does not need to be hard coded like the previous exa Which would return: -``` +```html

The default function helps make your templating DRYer.

``` diff --git a/content/en/functions/delimit.md b/content/en/functions/delimit.md index 4705a7f2d..63207b268 100644 --- a/content/en/functions/delimit.md +++ b/content/en/functions/delimit.md @@ -21,7 +21,7 @@ aliases: [] `delimit` called in your template takes the form of -``` +```go-html-template {{ delimit array/slice/map delimiter optionallastdelimiter }} ``` diff --git a/content/en/functions/echoparam.md b/content/en/functions/echoparam.md index 515b5c449..abdd0072a 100644 --- a/content/en/functions/echoparam.md +++ b/content/en/functions/echoparam.md @@ -19,6 +19,6 @@ aliases: [] --- -``` +```go-html-template {{ echoParam .Params "project_url" }} ``` diff --git a/content/en/functions/eq.md b/content/en/functions/eq.md index d342a628a..47901f16e 100644 --- a/content/en/functions/eq.md +++ b/content/en/functions/eq.md @@ -19,6 +19,6 @@ aliases: [] --- -``` +```go-html-template {{ if eq .Section "blog" }}current{{ end }} ``` diff --git a/content/en/functions/errorf.md b/content/en/functions/errorf.md index 04fd0edb0..4e5160b25 100644 --- a/content/en/functions/errorf.md +++ b/content/en/functions/errorf.md @@ -22,11 +22,11 @@ Any ERROR will also cause the build to fail (the `hugo` command will `exit -1`). Both functions return an empty string, so the messages are only printed to the console. -``` +```go-html-template {{ errorf "Failed to handle page %q" .Path }} ``` -``` +```go-html-template {{ warnf "You should update the shortcodes in %q" .Path }} ``` @@ -38,7 +38,7 @@ Sometimes it may make sense to let the user suppress an ERROR and make the build You can do this by using the `erroridf` function. This functions takes an error ID as the first argument. -``` +```go-html-template {{ erroridf "my-custom-error" "You should consider fixing this." }} ``` diff --git a/content/en/functions/format.md b/content/en/functions/format.md index 5c86714fe..201a779cd 100644 --- a/content/en/functions/format.md +++ b/content/en/functions/format.md @@ -97,7 +97,7 @@ Spelled-out cardinal numbers (e.g. "one", "two", and "three") are not currently Use the [`humanize`](/functions/humanize) function to render the day of the month as an ordinal number: -``` +```go-html-template {{ humanize .Date.Day }} of {{ .Date.Format "January 2006" }} ``` diff --git a/content/en/functions/ge.md b/content/en/functions/ge.md index c7256c0e3..915930528 100644 --- a/content/en/functions/ge.md +++ b/content/en/functions/ge.md @@ -19,6 +19,6 @@ aliases: [] --- -``` +```go-html-template {{ if ge 10 5 }}true{{ end }} ``` diff --git a/content/en/functions/gt.md b/content/en/functions/gt.md index 91203f890..9643ee36d 100644 --- a/content/en/functions/gt.md +++ b/content/en/functions/gt.md @@ -19,6 +19,6 @@ aliases: [] --- -``` +```go-html-template {{ if gt 10 5 }}true{{ end }} ``` diff --git a/content/en/functions/i18n.md b/content/en/functions/i18n.md index 8f8c9642c..1dbbfcb76 100644 --- a/content/en/functions/i18n.md +++ b/content/en/functions/i18n.md @@ -23,7 +23,7 @@ aliases: [] This translates a piece of content based on your `i18n/en-US.toml` files. You can use the [go-i18n](https://github.com/nicksnyder/go-i18n) tools to manage your translations. The translations can exist in both the theme and at the root of your repository. -``` +```go-html-template {{ i18n "translation_id" }} ``` @@ -35,7 +35,7 @@ This translates a piece of content based on your `i18n/en-US.toml` files. You ca Often you will want to use the page variables in the translation strings. To do so, pass the `.` context when calling `i18n`: -``` +```go-html-template {{ i18n "wordCount" . }} ``` diff --git a/content/en/functions/in.md b/content/en/functions/in.md index 7a8cb33eb..c1ef45629 100644 --- a/content/en/functions/in.md +++ b/content/en/functions/in.md @@ -22,11 +22,11 @@ The elements supported are strings, integers and floats, although only float64 w In addition, `in` can also check if a substring exists in a string. -``` +```go-html-template {{ if in .Params.tags "Git" }}Follow me on GitHub!{{ end }} ``` -``` +```go-html-template {{ if in "this string contains a substring" "substring" }}Substring found!{{ end }} ``` diff --git a/content/en/functions/index-function.md b/content/en/functions/index-function.md index 6ee46b4a8..970ee0c49 100644 --- a/content/en/functions/index-function.md +++ b/content/en/functions/index-function.md @@ -69,7 +69,7 @@ pop_metro = 1717900 The example we will use will be an article on Oslo, whose front matter should be set to exactly the same name as the corresponding file name in `data/locations/`: -``` +```toml title = "My Norwegian Vacation" location = "oslo" ``` @@ -81,8 +81,8 @@ This is where the `index` function is needed. `index` takes 2 parameters in this 1. The node path 2. A string corresponding to the desired data; e.g.— -``` -{{ index .Site.Data.locations “oslo” }} +```go-html-template +{{ index .Site.Data.locations "oslo" }} ``` The variable for `.Params.location` is a string and can therefore replace `oslo` in the example above: diff --git a/content/en/functions/int.md b/content/en/functions/int.md index 309368702..74a22714b 100644 --- a/content/en/functions/int.md +++ b/content/en/functions/int.md @@ -32,7 +32,7 @@ number representation. The `strings.TrimLeft` can be used for this purpose. -``` +```go-html-template {{ int ("0987" | strings.TrimLeft "0") }} {{ int ("00987" | strings.TrimLeft "0") }} ``` diff --git a/content/en/functions/intersect.md b/content/en/functions/intersect.md index 8d4c50fe2..4a645234f 100644 --- a/content/en/functions/intersect.md +++ b/content/en/functions/intersect.md @@ -21,7 +21,7 @@ A useful example is to use it as `AND` filters when combined with where: ## AND filter in where query -``` +```go-html-template {{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }} {{ $pages := $pages | union (where .Site.RegularPages "Params.pinned" true) }} {{ $pages := $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }} diff --git a/content/en/functions/isset.md b/content/en/functions/isset.md index 2bfc43203..2be8a1587 100644 --- a/content/en/functions/isset.md +++ b/content/en/functions/isset.md @@ -20,7 +20,7 @@ aliases: [] Takes either a slice, array, or channel and an index or a map and a key as input. -``` +```go-html-template {{ if isset .Params "project_url" }} {{ index .Params "project_url" }}{{ end }} ``` diff --git a/content/en/functions/jsonify.md b/content/en/functions/jsonify.md index 72ec4634b..ecb5264ee 100644 --- a/content/en/functions/jsonify.md +++ b/content/en/functions/jsonify.md @@ -26,7 +26,7 @@ the output will begin on a new line beginning with *prefix* followed by one or more copies of *indent* according to the indentation nesting. -``` +```go-html-template {{ dict "title" .Title "content" .Plain | jsonify }} {{ dict "title" .Title "content" .Plain | jsonify (dict "indent" " ") }} {{ dict "title" .Title "content" .Plain | jsonify (dict "prefix" " " "indent" " ") }} diff --git a/content/en/functions/last.md b/content/en/functions/last.md index 4a752cb82..63fdfa129 100644 --- a/content/en/functions/last.md +++ b/content/en/functions/last.md @@ -20,7 +20,7 @@ draft: false aliases: [] --- -``` +```go-html-template {{ range last 10 .Pages }} {{ .Render "summary" }} {{ end }} diff --git a/content/en/functions/le.md b/content/en/functions/le.md index 1ff0ac582..8df2f2479 100644 --- a/content/en/functions/le.md +++ b/content/en/functions/le.md @@ -19,6 +19,6 @@ aliases: [] --- -``` +```go-html-template {{ if le 5 10 }}true{{ end }} ``` diff --git a/content/en/functions/lt.md b/content/en/functions/lt.md index d2a234986..1e82270c3 100644 --- a/content/en/functions/lt.md +++ b/content/en/functions/lt.md @@ -19,6 +19,6 @@ aliases: [] --- -``` +```go-html-template {{ if lt 5 10 }}true{{ end }} ``` diff --git a/content/en/functions/markdownify.md b/content/en/functions/markdownify.md index d222a8eb6..44e4c9af6 100644 --- a/content/en/functions/markdownify.md +++ b/content/en/functions/markdownify.md @@ -15,7 +15,7 @@ deprecated: false aliases: [] --- -``` +```go-html-template {{ .Title | markdownify }} ``` diff --git a/content/en/functions/md5.md b/content/en/functions/md5.md index 2168034c4..0c9cabbdc 100644 --- a/content/en/functions/md5.md +++ b/content/en/functions/md5.md @@ -18,7 +18,7 @@ deprecated: false aliases: [] --- -``` +```go-html-template {{ md5 "Hello world, gophers!" }} ``` diff --git a/content/en/functions/ne.md b/content/en/functions/ne.md index e072993d2..e0fc93bbd 100644 --- a/content/en/functions/ne.md +++ b/content/en/functions/ne.md @@ -19,6 +19,6 @@ aliases: [] --- -``` +```go-html-template {{ if ne .Section "blog" }}current{{ end }} ``` diff --git a/content/en/functions/now.md b/content/en/functions/now.md index 24e1ab3f7..e54f952e8 100644 --- a/content/en/functions/now.md +++ b/content/en/functions/now.md @@ -22,7 +22,7 @@ See [`time.Time`](https://godoc.org/time#Time). For example, building your site on June 24, 2017, with the following templating: -``` +```go-html-template
© {{ now.Format "2006"}}
@@ -30,7 +30,7 @@ For example, building your site on June 24, 2017, with the following templating: would produce the following: -``` +```html
© 2017
diff --git a/content/en/functions/partialCached.md b/content/en/functions/partialCached.md index 2e79bb32f..ef29ae8a9 100644 --- a/content/en/functions/partialCached.md +++ b/content/en/functions/partialCached.md @@ -38,7 +38,7 @@ You can also pass additional parameters to `partialCached` to create *variants* If you need to pass additional parameters to create unique variants, you can pass as many variant parameters as you need: -``` +```go-html-template {{ partialCached "footer.html" . .Params.country .Params.province }} ``` diff --git a/content/en/functions/printf.md b/content/en/functions/printf.md index 8b12b9883..41e6524ff 100644 --- a/content/en/functions/printf.md +++ b/content/en/functions/printf.md @@ -19,10 +19,10 @@ deprecated: false See [the go doc](https://golang.org/pkg/fmt/) for additional information. -``` +```go-html-template {{ i18n ( printf "combined_%s" $var ) }} ``` -``` +```go-html-template {{ printf "formatted %.2f" 3.1416 }} ``` diff --git a/content/en/functions/render.md b/content/en/functions/render.md index 7e4015bf6..158721a27 100644 --- a/content/en/functions/render.md +++ b/content/en/functions/render.md @@ -23,7 +23,7 @@ This function is only available when applied to a single piece of content within This example could render a piece of content using the content view located at `/layouts/_default/summary.html`: -``` +```go-html-template {{ range .Pages }} {{ .Render "summary"}} {{ end }} diff --git a/content/en/functions/safeHTML.md b/content/en/functions/safeHTML.md index 5a0aa1e05..904547446 100644 --- a/content/en/functions/safeHTML.md +++ b/content/en/functions/safeHTML.md @@ -33,7 +33,7 @@ copyright = "© 2015 Jane Doe. © 2015 Jane Doe. <a href="https://creativecommons.org/licenses by/4.0/">Some rights reserved</a>.

``` diff --git a/content/en/functions/seq.md b/content/en/functions/seq.md index a880ec241..0314595d5 100644 --- a/content/en/functions/seq.md +++ b/content/en/functions/seq.md @@ -33,14 +33,14 @@ It's named and used in the model of [GNU's seq]. You can use `seq` in combination with `range` and `after`. The following will return 19 elements: -``` +```go-html-template {{ range after 1 (seq 20)}} {{ end }} ``` However, when ranging with an index, the following may be less confusing in that `$indexStartingAt1` and `$num` will return `1,2,3 ... 20`: -``` +```go-html-template {{ range $index, $num := (seq 20) }} $indexStartingAt1 := (add $index 1) {{ end }} diff --git a/content/en/functions/sha.md b/content/en/functions/sha.md index 24ad165a8..ba344fddf 100644 --- a/content/en/functions/sha.md +++ b/content/en/functions/sha.md @@ -20,14 +20,14 @@ aliases: [sha1, sha256] `sha1` hashes the given input and returns its SHA1 checksum. -``` +```go-html-template {{ sha1 "Hello world, gophers!" }} ``` `sha256` hashes the given input and returns its SHA256 checksum. -``` +```go-html-template {{ sha256 "Hello world, gophers!" }} ``` diff --git a/content/en/functions/strings.RuneCount.md b/content/en/functions/strings.RuneCount.md index de335f862..69c581746 100644 --- a/content/en/functions/strings.RuneCount.md +++ b/content/en/functions/strings.RuneCount.md @@ -19,7 +19,7 @@ aliases: [] In contrast with `strings.CountRunes` function, which strips HTML and whitespace before counting runes, `strings.RuneCount` simply counts all the runes in a string. It relies on the Go [`utf8.RuneCountInString`] function. -``` +```go-html-template {{ "Hello, 世界" | strings.RuneCount }} ``` diff --git a/content/en/functions/title.md b/content/en/functions/title.md index 28444f400..b6f752ac8 100644 --- a/content/en/functions/title.md +++ b/content/en/functions/title.md @@ -27,7 +27,7 @@ aliases: [] Can be combined in pipes. In the following snippet, the link text is cleaned up using `humanize` to remove dashes and `title` to convert the value of `$name` to Initial Caps. -``` +```go-html-template {{ range $name, $items := .Site.Taxonomies.categories }}
  • {{ $name | humanize | title }} ({{ len $items }})
  • {{ end }} diff --git a/content/en/functions/transform.Unmarshal.md b/content/en/functions/transform.Unmarshal.md index 9b380dc57..cefee1503 100644 --- a/content/en/functions/transform.Unmarshal.md +++ b/content/en/functions/transform.Unmarshal.md @@ -52,7 +52,7 @@ As a convenience, Hugo allows you to access XML data in the same way that you ac To get the contents of `` in the document below, you use `{{ .message.title }}`: -``` +```xml <root> <message> <title>Hugo rocks! @@ -63,7 +63,7 @@ To get the contents of `` in the document below, you use `{{ .message.tit The following example lists the items of an RSS feed: -``` +```go-html-template {{ with resources.Get "https://example.com/rss.xml" | transform.Unmarshal }} {{ range .channel.item }} <strong>{{ .title | plainify | htmlUnescape }}</strong><br /> diff --git a/content/en/functions/trim.md b/content/en/functions/trim.md index 2cda7a59a..e688924bb 100644 --- a/content/en/functions/trim.md +++ b/content/en/functions/trim.md @@ -25,13 +25,13 @@ deprecated: false `trim` *requires* the second argument, which tells the function specifically what to remove from the first argument. There is no default value for the second argument, so **the following usage will not work**: -``` +```go-html-template {{ trim .Inner }} ``` Instead, the following example tells `trim` to remove extra new lines from the content contained in the [shortcode `.Inner` variable][shortcodevars]: -``` +```go-html-template {{ trim .Inner "\n" }} ``` diff --git a/content/en/functions/union.md b/content/en/functions/union.md index 465abcdd8..312bc5e65 100644 --- a/content/en/functions/union.md +++ b/content/en/functions/union.md @@ -20,7 +20,7 @@ aliases: [] Given two arrays (or slices) A and B, this function will return a new array that contains the elements or objects that belong to either A or to B or to both. The elements supported are strings, integers, and floats (only float64). -``` +```go-html-template {{ union (slice 1 2 3) (slice 3 4 5) }} <!-- returns [1 2 3 4 5] --> @@ -38,7 +38,7 @@ Given two arrays (or slices) A and B, this function will return a new array that This is also very useful to use as `OR` filters when combined with where: -``` +```go-html-template {{ $pages := where .Site.RegularPages "Type" "not in" (slice "page" "about") }} {{ $pages = $pages | union (where .Site.RegularPages "Params.pinned" true) }} {{ $pages = $pages | intersect (where .Site.RegularPages "Params.images" "!=" nil) }}