Partials not working as per docs

I’m getting pretty frustrated, but nothing is working for me as per the documentation.

I’ve created a new Hugo site and installed the Docsy theme as a submodule at themes/docsy. I have a home page, at content/index.html, and I’m just trying to render a partial. Here is my index.html file:

---
title: Home
---
{{ partial "platform.html" . }}

Here is the contents of layouts/partials/platforms.html:

<p>Platform?</p>

It doesn’t work. The literal string just gets printed to the browser instead of the contents of the partial file.

If fact, it seems as if nothing dynamic is working as per the Hugo docs. The same for things like ranges. Any time I try and do something with curly brackets, it just gets printed as-is instead of being parsed by Hugo.

What am I doing wrong?

Partials are layout files that you can use in layout files. NOT in content files. To implement a partial in a content file (Markdown) you need to create a shortcode for that partial:

// layouts/partials/platform.html
<some><code>bla</code></some>
// layouts/shortcodes/platform.html
{{ partial "platform" . }}
// content/some/path/index.md
{{< platform >}}

In short:

  • partial → use in layouts
  • shortcode → use in markdown

Sidenote: Use this approach ONLY if you want to use the code for platform in layout files AND content files. If you are using that only in your content then put the partial content into the shortcode file.

1 Like

Thanks for the speedy reply, @davidsneighbour. Makes sense; thanks for clearing that up for me!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.