2019-10-21 04:22:28 -04:00
---
2023-10-20 03:42:39 -04:00
title: collections.Querify
2021-06-18 11:49:54 -04:00
description: Takes a set or slice of key-value pairs and returns a query string to be appended to URLs.
2023-12-04 09:14:18 -05:00
categories: []
2023-10-20 03:42:39 -04:00
keywords: []
2023-12-04 09:14:18 -05:00
action:
2023-10-20 03:42:39 -04:00
aliases: [querify]
returnType: string
signatures:
2023-12-04 09:14:18 -05:00
- collections.Querify VALUE [VALUE...]
2023-10-20 03:42:39 -04:00
- collections.Querify COLLECTION
2023-12-04 09:14:18 -05:00
related:
2023-10-20 03:42:39 -04:00
- collections.Querify
- urlquery
aliases: [/functions/querify]
2019-10-21 04:22:28 -04:00
---
2021-06-18 11:49:54 -04:00
`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.
2019-10-21 04:22:28 -04:00
2021-06-18 11:49:54 -04:00
The following examples create a link to a search results page on Google.
2019-10-21 04:22:28 -04:00
2021-06-18 11:49:54 -04:00
```go-html-template
2019-10-21 04:22:28 -04:00
< a href = "https://www.google.com?{{ (querify " q " " test " " page " 3 ) | safeURL } } " > Search< / a >
2021-06-18 11:49:54 -04:00
{{ $qs := slice "q" "test" "page" 3 }}
< a href = "https://www.google.com?{{ (querify $qs) | safeURL }}" > Search< / a >
2019-10-21 04:22:28 -04:00
```
2021-06-18 11:49:54 -04:00
Both of these examples render the following HTML:
2019-10-21 04:22:28 -04:00
2021-06-18 11:49:54 -04:00
```html
2019-10-21 04:22:28 -04:00
< a href = "https://www.google.com?page=3&q=test" > Search< / a >
```