Update a partial with different parameters?

i have a partial that that takes in some parameters via a dictionary/map I use in list.html pages.

<button id="mybutton">
...
</button>

<div id="mylist">
{{ partial "partials/mypartial.html" $myparameters }}
</div>

is there a way to update/reload the partial with updated parameters?
I’ve been using jquery to try to add some dynamic functionality.

for example I want to do something like:

$('#mybutton').click( function () {
    let updatedParams = {...}
    $('#mylist').empty();
    $('#mylist').html(
        `{{ partial "partials/mypartial.html" ${updatedParams} }}`
    );
})

^^ or something like that, you get the idea!

Hugo is a static site generator. It looks like you want Hugo to do something dynamically when a user is visiting a page. Find another way.

show whats in mypartial, so we can find a way.

1 Like

Thanks so much Tom!!
mypartial displays posts based on which tags are “selected”

# mypartial.html
# {{ $myparamters :=  (dict 
#        "allposts" .Site.RegularPages 
#        "selectedTags" (slice "tag1" "tag2" "tag3")) }}

{{ $postsToDisplay := slice }}
{{ range $post := .allposts }}
    {{ range $tag := .Params.myCustomTags }}
        {{ if in $.selectedTags $tag }}
            {{ $postsToDisplay = append $post $postsToDisplay }}
        {{ end }}
    {{ end }}
{{ end }}

{{ $postsToDisplay = uniq $postsToDisplay }}
{{ range $postsToDisplay }}
    # normal list styling...
{{ end }}

I want to be able to be able to change selectedTags reload the partial with the updated selectedTags

You can’t “reload” a partial because there is no partial anymore at the time your user clicks on a tag. Use JavaScript top achieve what ever it is you want to achieve. And perhaps read up about static site generators – they build everything before your users get to see it, and when they get to see your site, Hugo is not involved anymore.

2 Likes

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