I’m putting together a small e-commerce site and giving Hugo a try. I’ve got an index page built and a couple other static pages (About, contact us) also working. Now I’m getting into more content and data and not understanding how to build links in the template or set up the data or content files.
I have an index page - a section of that page has a image/link for each product, this is pulled from data files. Sample code:
The index page displays the product image and details from the data file just fine. My next step is to add in the proper link in the two “a href=”#"" portions. I’ve got a product details html file. I’m not sure where to place that or how to build the links to the details page.
I suspect I need to put something in the product-details.html in site root/layouts/products. And I’d probably put a URL element in my product TOML file too. But how does this work so that the product-details.html is built with the data in the product TOML?
Well, you could add a section for the product details under content and use new version 0.32’s bundling feature.
That way you could make a folder for each product, and include details files under there, either in each folder’s index.md or, in a referenced file, and, any images of the product. I am not sure if the referenced file can be anything, or, if your html files would suffice.
As for the links, have you tried adding a line or lines in each data file for those href s? Once you get the product details files set, you’ll know what their URLs are, and then you could add those to your data files.
Btw, I saw your first code block worked and your second didn’t. The first was indented enough but the second wasn’t so I added “fencing” around the second. Edit to see it. It’s just five tildes before and after. I like it better since indenting in here is a bit of a pain.
I’ve just now read through bundles segment you pointed me to, and I rather like this organization so I think I might try that. In reading that, it has lead me down another path of reading.
I think there is still some short comings in my understanding, let me try something with the bundles and see what I get. I’ll post back with results.
{{ range where .Site.Pages.ByWeight "Section" "products" }}
I get the following kind of links:
/products/
/products/prod1/
/products/prod2/
/products/prod3/
etc.
I’d like to not get an output for /products/, just the /products/prod1/. Is there a way to suppress or eliminate an output from the /products/? I’m using this range capability to list the actual products.
GetbyPrefix is exactly what it sounds like. You are using it in conjuction with a permalink that you are getting with print. So it’s natural that you’re getting an error.
I’ve been through the 0.32 doc and repo a couple times and have spent 30 minutes trying several things. Of course I’m finding new things in the documentation, However i’m still missing something or not seeing and understanding what I need to for my task at hand.
Right now I’m trying to access the other .md files in the bundle. (I’m really glad I was pointed to the bundle of 0.32, it is the organization I need)
The Params in index.md I can access and use. The Content index.md I can use as well.
However I can’t figure out how to get the Content of desc_short.md.
if I do this:
{{ with .Resources.ByType "page"}}
{{ . }}
{{ end }}
I have been able to get that example to run. I think there is some oddity in that output in that I’m seeing multiple content, however I haven’t dove into that.
This example though still doesn’t show me what I need. I don’t want to loop or range over the .mds. I want to get the Content of a specific .md at point A in my template and content of a different .md at a point B in my template. My thought was that I’d be able to reference the .md. So I’ve been trying to limit ByPrefix or GetPage but I’m not having success.
Another item tried, but failed. My thinking was the first line gets the pages in the bundle (it does). The second line gets the specific page. But it errors.
{{ with .Resources.ByType "page" }}
{{ .GetPage "desc_short" }}
{{ .Content }}
{{ end }}
Error:
.....at <.GetPage>: can't evaluate field GetPage in type []resource.Resource