How to read query parameters in template

I have a hugo template and I am giving hyperlink from one page to another page. I would like to pass some query parameters in the URL and read them in the template.

/list-page/?{{(querify "somekey" "value")}}

what I want to do is to check in /list-page/ if there is a ?somekey=value in the url. if there is, I would like to filter the list according to the parameter passed. If not, I will display the entire list. If it is not clear, I can try to explain more. I have tried {{ $value := (.Get "value") }} But this brakes it. it does not work at all. I am using Hugo Static Site Generator v0.55.6 Any help is appreciated.

Hugo is a static site generator and, by definition, does not provide dynamic views of content.

Perhaps you can leverage Taxonomies to meet your needs…

Like @jmooring wrote: static.


I would solve it this way:

  • create blocks around the things you want to show/hide
  • give them classes like somekey_has_value or something like that so you find them
  • use javascript that reads the parameters and shows/hides the blocks

Advantage: Search engines will see one page with all items
Disadvantage: You need some Javascript magic.

1 Like

That is an interesting way to get the effects of a dynamic web page within the static framework! You could even have buttons on the page to filter the list (and even update the query in the URL…). I’ll have to try this!

Well, yes. Thank you guys all. In the end I decided to read the url parameters with javascript in the page and filter the results accordingly. I was expecting to see a flash between unfiltered/filtered items in the page but luckily that was not the case.