Partials with Markdown content

I am working on converting my companies website over to be done in hugo, but unfortunately the best way to maintain my layout is by using lots of partial templates to essentially give the website a ‘block’ style layout. I am creating a new theme to do this but I am running into an issue where I will have to have basically an end user changing the markdown content of the website as the website needs updates. Well the bulk of this content is contained inside a various partial templates. Is there a way to have a partial template use an it’s own markdown file? Sorry if I have poorly explained this, I can try to elaborate better if needed.

  • If this is markdown file not also present as content pages, you could use the readFile "" | markdownify – but I would then recommend using the partialCached func.
  • If this is existing pages, I have just updated (i.e. not released yet) the GetPage func to also handle regular pages, so in the next Hugo (or the current development version), you could do `{{ (.Site.GetPage “blog/”).Content }}``
  • Then there is also the /data files, which also can be sent into the markdownify func.

Unfortunately no. There is no way to use a partial in a content file. I understand what you’re trying to achieve though. And I am currently in a similar situation as you.

The above answer by @bep looks interesting. I wasn’t aware of the readFile function.

I will note it one more time, because it is important, the readFile has no caching whatsoever, so if you include it in the single.html template on a site with 10,000 pages, that same file will be read 10,000 times, so use partialCached.

1 Like

If you want include one content file in another mmark support this feature.

@Netross I’d be interested to hear more about what you’re trying to accomplish with box layouts. Do you have a repo to share, a spec, or a mockup so I can get a better sense of it? It’s something that should be fairly straightforward in Hugo.

@bep I will have to look into the partialCached function more, but I am very interested in the GetPage function that is un-released.
@budparr I unfortunately cannot share the repo with anyone, but to better describe the ‘block’ content, think of a one page style website where they have separate sections of the same page all for different information. Well for our website almost every page is like that, but it is a large website and on every page each section is different than the next, and all of that content needs to be able to be changed by a markdown file. If I were able (which I may be) to make each section (or block) a partial template attached to a markdown file, that would be the easiest way to achieve the end goal I am after. I will explore my options with the suggestions that @bep made and see what I can do.
I am also very new to hugo so that has a lot to do with the struggle I am having as well.

A note on the unreleased remark: The Hugo master branch has proven to be very stable, so if you really need an unreleased feature, getting a development version would be a good way. Either by compiling one yourself, or I believe you could also get one via Brew on macOs.

Okay, so I’m not sure if this is helpful, but, consider this content, where you can boxed content of a sort listed in front matter (you can get quite elaborate with front matter, by the way):

That “features” section is rendered in this partial:

I have a more elaborate example with much more content, but I wrote that one a while back (I’m still relatively new to Hugo and learning, myself), but suffice to say, it sounds like what you’re trying to do can be done quite efficiently with Hugo.

Hope that’s helpful!


I’m looking into this myself, and it appears that there is, used in the universal theme.

The file has it’s yaml like so:

title = "Contact" 
id = "contact" 

The id = "contact" line seems to be referring to this partial ‘contact.html’. You can see that it is supplying not only the contact.html partial with the formspree contact form, but also plumbed into another partial map.html which itself is displaying the JavaScript output of the
gmaps.init.js file.