How to change or Add url query in Hugo

For example have an url like or Now I want change url to
Here is my code:

{{ $u := urls.Parse "" }}
{{ $u.Query Set "test2" "2" }}
{{ printf "%#v" $u }}

I got error: <$q.Set>: can’t call method/function “Set” with 0 results

Please help.

The result of the Hugo urls.Parse template function is immutable. You cannot use the Add, Del, or Set methods within a Hugo template.

You will have to construct the new URL manually using print or printf.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.