Using the right template

Another newbie question (how many of these can I have before someone blocks me?)

I have a simple theme. In addition to the default templates (index, single, list) I have created a tags.html and put it in the _default folder.

Then in my content, I have two folders:

The intention is that everything in posts should use the single.html template, which it does.

However I want everything in tags to use the tags.html template. Which it doesn’t.

I understood from the help docs that Hugo would look for the template that matches the name first, and then fall back on single if nothing matching was found?

However, judging by point 14 on this page, it has to be done manually:
(@delay brilliant post by the way)

Can anyone clarify if there should be some automatic way, or if I need to use the technique at that link?

Related question: under what circumstances would it fall back to list rather than single?

First question is why you are creating a content folder for tags? Have you looked into taxonomies. Once you answer that, maybe I can help. Would you mind showing us the rest of your source organization as well?

Off the bat, I’m thinking you can just create a template at layouts/tags/single.html, but you are probably doing more work than necessary since Hugo has built-in support for taxonomies.

So, I have tags appearing on my index page, which link through to . . . nothing, unless I create a landing page for them.

All my source code (theme and content) can be found here:

Edit for correct link


Alrighty, so a few things:

  1. I know Dropbox seems very convenient right now, but ultimately I’d recommend learning about a basic git flow and putting your code into a proper DVCS (version control). I’m a fan of Atlassian’s tutorials, but you’ll ultimately probably end up using GitHub for your hosted git solution. This is going to make it easier for you to revert to previous versions, run continuous deployment/integration, share code with collaborators (including the good folks in this forum), etc. I know you said you’re a newb, and it’s a lot to take in. If you have the resources, I’d also recommend Git for Humans (or any other book in the ABA series).
  2. Read the documentation on taxonomies. Here is the first step to fixing your config.toml:
theme = "chipButtyBellsOn"
baseurl = ""
languageCode = "en-uk"
title = "My New Hugo Site"

  tag = "tags"
  1. Now, in layouts/_default/terms.html use whatever header and footer you want to keep across all your pages, and add something like the following. I’m not saying you need to use this, but it will give you an idea of how taxonomies work:
<ul class="tags">
	    {{ $data := .Data }}
	    {{ range $key,$value := .Data.Terms.ByCount }}
	    <li class="site-tag">
			<a href="/{{ $data.Plural }}/{{ $value.Name | urlize }}">{{ replace $value.Name "-" " " | upper }} ({{ $value.Count }})</a>
	    {{ end }}

Hope that helps.

Thanks for this!

I am using git for the themes themselves, just not the whole site.

I will give your example a try. I had already read about taxonomies but was still a bit fuzzy about them.

I think the problem is, the documentation assumes a certain level of knowledge (which is fair enough, most people coming here will have that knowledge). I’ve never used anything like this before - never used Jekyll, never even got into Wordpress or such like. So I need to start with the really basic level of ‘what is a taxonomy and why would you use one’ :stuck_out_tongue:

@StarfallProjects Here is an example of how to call those tags on your homepage (and have them link to the appropriate page) once you’re comfortable with using taxonomies:

<ul class="site-tags">
    {{range $name,$taxonomy := .Site.Taxonomies.tags}}
        <li><a href="/tags/{{$name}}">{{replace $name "-" " "}}</a></li>

I think the Hugo docs in this regard are better than most for SSGs:

@rdwatters Thanks for sharing a link to this tutorial! Helped me alot!