querify.md (1008B)
1 ---
2 title: querify
3 linktitle: querify
4 description: Takes a set or slice of key-value pairs and returns a query string to be appended to URLs.
5 date: 2017-02-01
6 publishdate: 2017-02-01
7 lastmod: 2017-02-01
8 categories: [functions]
9 menu:
10 docs:
11 parent: "functions"
12 keywords: [urls]
13 signature: ["querify KEY VALUE [KEY VALUE]...", "querify COLLECTION"]
14 hugoversion:
15 deprecated: false
16 workson: []
17 relatedfuncs: []
18 aliases: []
19 ---
20
21 `querify` takes a set or slice of key-value pairs and returns a [query string](https://en.wikipedia.org/wiki/Query_string) that can be appended to a URL.
22
23 The following examples create a link to a search results page on Google.
24
25 ```go-html-template
26 <a href="https://www.google.com?{{ (querify "q" "test" "page" 3) | safeURL }}">Search</a>
27
28 {{ $qs := slice "q" "test" "page" 3 }}
29 <a href="https://www.google.com?{{ (querify $qs) | safeURL }}">Search</a>
30 ```
31
32 Both of these examples render the following HTML:
33
34 ```html
35 <a href="https://www.google.com?page=3&q=test">Search</a>
36 ```