mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Merge commit 'e9fbadacc3f09191e2e19f112a49777eeb8df06c'
This commit is contained in:
@@ -7,7 +7,7 @@ action:
|
||||
aliases: [dict]
|
||||
related:
|
||||
- functions/collections/Slice
|
||||
returnType: mapany
|
||||
returnType: map[string]any
|
||||
signatures: ['collections.Dictionary [VALUE...]']
|
||||
aliases: [/functions/dict]
|
||||
---
|
||||
|
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: collections.Querify
|
||||
description: Returns a URL query string composed of the given key-value pairs.
|
||||
description: Returns a URL query string composed of the given key-value pairs, encoded and sorted by key.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
@@ -13,18 +13,18 @@ action:
|
||||
aliases: [/functions/querify]
|
||||
---
|
||||
|
||||
Specify the key-value pairs as individual arguments, or as a slice. The following are equivalent:
|
||||
|
||||
Specify the key-value pairs as a map, a slice, or a sequence of scalar values. For example, the following are equivalent:
|
||||
|
||||
```go-html-template
|
||||
{{ collections.Querify "a" 1 "b" 2 }}
|
||||
{{ collections.Querify (dict "a" 1 "b" 2) }}
|
||||
{{ collections.Querify (slice "a" 1 "b" 2) }}
|
||||
{{ collections.Querify "a" 1 "b" 2 }}
|
||||
```
|
||||
|
||||
To append a query string to a URL:
|
||||
|
||||
```go-html-template
|
||||
{{ $qs := collections.Querify "a" 1 "b" 2 }}
|
||||
{{ $qs := collections.Querify (dict "a" 1 "b" 2) }}
|
||||
{{ $href := printf "https://example.org?%s" $qs }}
|
||||
|
||||
<a href="{{ $href }}">Link</a>
|
||||
@@ -35,3 +35,16 @@ Hugo renders this to:
|
||||
```html
|
||||
<a href="https://example.org?a=1&b=2">Link</a>
|
||||
```
|
||||
|
||||
You can also pass in a map from your site configuration or front matter. For example:
|
||||
|
||||
{{< code-toggle file=content/example.md fm=true >}}
|
||||
title = 'Example'
|
||||
[params.query]
|
||||
a = 1
|
||||
b = 2
|
||||
{{< /code-toggle >}}
|
||||
|
||||
```go-html-template
|
||||
{{ collections.Querify .Params.query }}
|
||||
```
|
||||
|
Reference in New Issue
Block a user