Generating templated pages with sections

First of all, there will be an update to post archetypes in the next Hugo version. See here: "The Revival of the Archetypes!": Please take it for a spin if you can!

Other than that there are a number of ways to achieve what you need.

Here are a few examples

Say you have a products section under /content/products/ then the template for the list page of your products goes under /layouts/section/products.html . Anything you put in this template will be rendered whenever you visit: http://example.com/products

For markup specific to the individual product pages you can put it inside your /layouts/_default/single.html like this:

{{if eq .Section "products"}}
Markup for product pages goes here
{{ end }}

For special “product sections” (as you call them) you could specify parameters in your products’ front matter like so:

+++
description = "Lorem Ipsum Dolor Si Amet"
barcode = "Some code"
+++

And then in the above section of single.html call them like this:

{{ with .Params.description }}<p class="product-description">{{ . }}</p>{{ end }}

For a support widget the code goes under /layouts/partials/support.html

And in your single.html you will call it like this: {{ partial "support.html" . }}

Then to pass a product’s barcode to your support widget from the specified parameter in your front matter (see above) you can do it like this:

{{ with $.Page.Params.barcode}}<h4>Barcode: {{.}}</h4>{{end}}

Your questions are very broad indeed. And I have addressed some of the ways to achieve what you want. Not all. But you should get a start on how to go about making a product catalog with Hugo.

1 Like