A Hugo method to store the index of slices

I have an array ‘products’ that holds data of a few products:

products:
  - image: 
    item: 
    description: 
    tags: 
    price: 
    oldprice: 
    weight: 

Uing range functin I can loop through the slices of the array viewing products one by one.

1.Is there a Hugo method to store the index of slices so that I could later access an element using an expression like

{{ (index .products $index).item }}?
  1. Is there a method to copy a slice on a mouseclick?

I need to transfer one slice to the purchase processing section.

The click happens at runtime. Hugo is not running then anymore, and there isn’t a “sice” either.

Whenever you think “click”, the answers are “JavaScript” or “serverside”.

Yes, I know mouseclick happens on client side, while Hugo operates on server side. I asked just in case maybe someone knows a knowhow.
BTW I could save the index, but I could not use it to access an element using the expression

{{ (index .products $index).item }}

I suppose it needs a page update.
I wonder if someone had this experience.

Not true. Hogo is running on the sources. Not on server side

Maybe a little more context will help.

  • the markdoen file
  • templates
  • data file

As @irkode said: Hugo is not operating anywhere when a click happens. Hugo has terminated whatever it’s doing (and no, you shouldn’t use Hugo instead of a web server).

If you need a “page update”, you must run hugo and deploy your site again. If you need to modify the DOM of the page, you need JavaScript.

But as already pointed out: your questions are far too vague and general to be answered sensibly.

1 Like

As everyone on this thread has advised, there is no way (known to me) to do what you want using Hugo alone. You will need three things in addition to your Hugo generated static javascript client, (1) A service-like API with put, retrieve and delete like endpoints OR a browser backed local storage with all its weaknesses and vulnerabilities (2) Some kind of persistent storage and (3) A session manager (to remove products after checkout)

I have done this (for user comments on Hugo blogs etc, not products) and I would advise you to consider other complementary strategies that might be better suited. If you still want to try, I would like to add that Hugo has excellent support for integrating and managing client-side Javascript (with the js.Build call) so make sure you have had a good look at the documentation and examples.

Hugo is exceptionally good at what it does. But what it does might not be, ideally, good for your goal.

Thank you everybody!

Just to mention there’s a way

Depending on the amount of data, you could generate many pages

You could also add the data in frontmatter and add a page for every product.

generate the matching menus. Navigation

Buzzwords would be

  • content adapter
  • pagination
  • menu

But as a result static pages for multiple products