Hugo

Templates written in markdown?

I currently have a baseof.html, list.html and single.html template in my layouts folder. However, I prefer the markdown syntax over html. So I wanted to change the single.html and list.html file to a markdown file.

Though when I change single.html to single.md the template doesn’t work anymore. As it expects the file to be an html file.

So I was wondering, is there a way to write templates in markdown? As I prefer the markdown syntax. Or is there a way I can use markdown inside the single.html file?

No, markdown is for writing human readable text.

You might be looking for a system that makes presumptions about your output, whereas Hugo requires templates to generate output.

Yes exactly, I prefer to read markdown, so would love to be able to use it even for templates. Makes sense that the baseof template has to be html, because there are parts that can’t be defined in markdown, but I found many parts of the template can just as well be defined in markdown.

But fair enough, html for templates and markdown for content is acceptable.

Thanks!

Such as? Please provide an example of what you mean.

For instance for the recipe site I’m making, I’m auto-generating the list of ingredients at the top. This way it’s easy to make the ingredients link to the taxonomy pages and such.

Anyway, it’s basically just a list at the top of the page.

The way markdown defines lists is much nicer than html, so that’s a good example.

I also show the name of the recipy at the top of the page.

<h1>{{ .Title }}</h1>

<h1>Ingredients</h1>

<ul class="ingredients">
    {{ range $name, $description := .Params.ingredients }}
    <li>{{ $description }}</li>
    {{end}}
</ul>

versus

# {{ .Title }}

# Ingredients

{{ range $name, $description := .Params.ingredients }}
* {{ $description }}
{{end}}
{: .ingredients}

The main part I found that can’t be defined in markdown is stuff in the head, so that has to be defined in the baseof.html.

Or am I using templates wrong?

No, you are using markdown wrong. :slight_smile:

Markdown has to be processed to produce HTML. That’s markdown’s whole thing, ne? So we have this limited by easy to remember core set of assumptions, and then a “flavor” or standard markdown implementation is coded to parse any customization; code-fences, for instance, or the so-called GitHub-style checkboxes.

Dope.

Markdown is for humans to write bothersome HTML code real fast, and human-readable.

Templates are for computers to parse and produce output from. You aren’t producing human content, you want to use markdown to produce computer code.

I’ve got no problem with that, but that isn’t what Hugo does. Hugo is a static-site generator. It has some nice-to-have features that provide scaffolding for themes and such, but it does not come with that level of template-scaffolding.

You might be better off looking for an IDE with macro support for your use case. :sunglasses: