Capture user input and pass it into a hugo variable

How do I capture user input (ideally without a full form) and pass the selection back into a hugo variable?

 {{ $user_filter := user_selection }}

My code works just fine when I give $user_filter a static value: {{ $user_filter := "StaticValue" }}, but of course I want the user selection instead.

I have the following selection code and filter code - but I am not sure how to take the selection (probably with JS and pass it into the $filter variable – ideally, I’d like a very simple solution. Also it would be handy if ‘All’ could disable the filter.

I’ve tried to understand the Academy code wowchemy-hugo-themes/portfolio.html at main · wowchemy/wowchemy-hugo-themes · GitHub – but I don’t understand. I also tried to find the code for Wochemy’s publications form - but somehow it eluded me

<div class="row mb-5 mt-4 d-flex justify-content-center">
  <div class="btn-group btn-group-sm" role="group" aria-label="Basic example">
    <button type="button" class="btn btn-secondary">All</button>
    {{ $tags := $.Site.Taxonomies.groups.Alphabetical }}
    {{ range $tags }}
    {{ if .Term }}
    <button type="button" class="btn btn-secondary">{{ .Term }}</button>
    {{ end }}
    {{ end }}

{{ $user_filter := "Sustainability" }}

{{ range where (where site.RegularPages "Type" "network") "" "==" $user_filter }}
<div class="row">
  HTML Layout

PS - if it’s easier I can use a dropdown or a form in absolutely needed. But I would prefer a few buttons.

You can’t. Hugo is a static website generator.

hmmm - bummer - I guess I will need to do that with JS. Bummer. Not one of my favorites.

I guess I can just make a page for each key to start and the links just go to that page.

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