Skip to content

How to build the querystring of an URL? #388

Answered by joerdav
guettli asked this question in Q&A
Discussion options

You must be logged in to vote

Currently you would have to adopt one of 2 approaches:

Probably the more "proper way":

func buildRowUrl(query string) string {
    u, _ := url.Parse("/")
    q := url.Values{}
    q.Set("page", "0")
    q.Set("query", query)
    u.RawQuery = q.Encode()
    return u.String()
}

templ row() {
    	<tr
		hx-get={ buildRowUrl(query) }
		hx-trigger="revealed"
		hx-swap="afterend"
	></tr>
}

The shorter way:

templ row() {
    	<tr
		hx-get={ "/?page=0&query=" + url.QueryEscape(query) }
		hx-trigger="revealed"
		hx-swap="afterend"
	></tr>
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by guettli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants