Pass information from one page to another

I have several portfolio pages. All of the items featured in these portfolios use the same template for their detail pages. The detail page has a back button, and we want that button to take people back to the portfolio page they came from. But items can appear in multiple portfolios. I need a way to tell the detail template what portfolio page the user came from.

Originally I wanted to use a query string in the url, so clicking an item on a portfolio page would take you to “domain/item/?portfolio=1” but I can’t figure out how to get the query string in my template so I could add that information to the back button. Is there a way to grab a query string in hugo or is there a better way to pass information between pages?

I am afraid it cannot be done since the static pages do not have any logic.

You have to consider using javascript for any usage of query parameters.

that’s a real bummer

Try Googling html5 navigate back. It’s not a lot of work and there are JS libraries to help.

You could load the detail pages with Ajax on the actual index page and change the URL with history.replaceState

This way no matter how many items are loaded the user will always return to the original portfolio page if they press the browser’s back button.

To make an HTML back button you could use something like
<a href="javascript:history.back()">Back</a>