I am trying to have a shortcode to display datas from a json file as a table or a list using the new function transform.Unmarshal.
For example having the following json file:
{ "device": "item 1",
"brand": "Brand 1",
"category": "Cat 1" },
{ "device": "Item 2",
"brand": "Brand 2",
"category": "Cat 2" },
{ "device": "Item 3",
"brand": "Brand 2",
"category": "Cat 2" },
{ "device": "Item 4",
"brand": "Brand 3",
"category": "Cat 3" },
{ "device": "Item 5",
"brand": "Brand 1",
"category": "Cat 1" }
I would like to get a table or list or tabs selection to display all items per Category (and possibly to count them).
The json file (whislist.json) could be located in page bundle or in assets/data.
I put the wishlist.json file in page bundle (content/news/wishlist/...)
I am trying to follow [the Hugo docs]( transform.Unmarshal ) with the shortcode wishlist.html as follows:
{{ $data := dict }}
{{ $path := "wishlist.json" }}
{{ with .Resources.Get $path }}
{{ with . | transform.Unmarshal }}
{{ $data = . }}
{{ end }}
{{ else }}
{{ errorf "Unable to get page resource %q" $path }}
{{ end }}
{{ range $category, $device := .Site.Data.wishlist }}
<p>{{ $category | title }}</p>
<ul>
{{ range $device }}
<li>{{ . }}</li>
{{ end }}
</ul>
{{ end }}
Unfortunately I get the following error :
failed to extract shortcode: template for shortcode "wishlist" not found
Thanks for your help and guidance