I want to use the same template (list.html) for a section list and also a tag list. I can do this by putting the same list.html template in
/layouts/thesection/list.html
and
/layouts/tags/list.html
This works but is there a recommended way to do it without having to duplicate code? I don’t want to use this template everywhere, just these two places.
I guess you can specify a frontmatter field called layout. So, it can look like layout: "name" and then create a file in layouts/page/name.html. I use this for single pages, not sure if it will work for list pages, but you can try.
if your list template is generic enough to work as a base for all list pages, Hugo will fall-back to using layouts/_default/list.html for both your section and the taxonomy lists.
But you say you don’t want to use this template everywhere.
Depending on your code, you could look into using content view templates if there are parts of your list that you can usefully abstract like this: https://gohugo.io/templates/views