Use markdown in my index.html page?

I am using Hugo 0.16. (I cannot upgrade to Hugo 0.18)

My entire site is written in Markdown except the home page in /layouts/index.html That page (obviously) has the template for the site, but the content there has HTML markup.

Is there a way to use Markdown text there? Many thanks.

In a roundabout way:

{{ "This is some **markdown**" | markdownify }}

That’s very helpful. One follow-on question:

Is there some kind of ‘include’ facility that would allow me to place the actual content of the index.html page in the /content/ directory? That would keep all the content for the site in one place…

I’m hoping there’s a way to do something like:

{{ {{ include /content/index.md }}  | markdownify }}

Thanks again!

You can use content/_index.md Any markdown in that file will be available as {{ .Content }} in your index.html template. Hope that helps!

1 Like

That is a good sokution for Hugo 0.18.

Threaf starter asks about 0.16, and while there are potentual hacks via readFile, you are pushing the support for such an old Hugo version.

Ah, right. A little quick on the draw there

I will avoid replies by mobile in the future…

Not include since that’s not part of the Hugo syntax, but you can get close. I think this worked for me on an old site I built in 16 or 17:

  1. Create a partial in layouts/partials/homepage.html
  2. Write the text inside of homepage.html in markdown, even though it has the .html file extension.
  3. Use {{partial "homepage.html" . | markdownify }} in layouts/index.html.

That said, if you’re comfortable with the upgrade, it’s a lot less hackish to go the every-page-is-a-page route with _index.md, as mentioned by @budparr.

HTH.