Generate getJSON based on url

I have a page, where i get data from an external API service.

I can all all data by using “url/data/all”
Byt for most cases, it would be better, if the user, can click a link, and select a country.
The api support this by using “url/data/country”

Is there a clever way, i can modify the url, based on a link, or some other way (in case this is not the correct way of doing this).

The only way i see it right now, is to create a page, for every country i have, and that is a hassle to maintain.


Hugo is a static site generator.

The getJSON function is not dynamic, it only works when the static HTML is published.


So i’m asking because i’m trying to learn.

Is there another approach, i could take, to fix this, or is one page, pr. country the only way ?

With Hugo -as far as I know- there is no way to populate lists from remote APIs on demand.

Perhaps you could render these lists with JavaScript on the frontend, but I am not aware of a library that you could use, because I never had a need to use it.

Thanks. I will keep looking :slight_smile:

ok so i solved it.

My range in my partial.html files is set as : {{ range where $dataJ “country” }}

And in my front matter, i now have a : country: DK

Then i created a small python script, that pull each uniquecountry from the database, and created a page, with the name and country as the country.

Problem solved :slight_smile:

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