Process a partial template directly into html content

I want to generate HTML files in a subdirectory in the root of my hugo site that will be shared with other virtual hosts that are not hugo sites. These HTML files only need to contain the result of the processing of partial templates. Is this possible? I’ve tried different hacks to do this, but can’t get it to work.

structure

content/foo
├── foo-1.md
└── foo-2.md
layouts/foo
└── baseof.html

layouts/foo/baseof.html

{{ partial "bar.html" . }}

I’ve tried that. I also tried with “draft: false” in the .md files and

[outputs]
foo = [“html”]

in config.toml. Unfortunately, no joy. And there’s the additional problem that I need to generate two of those files with different content but in the same subdirectory.

I tried with shortcodes with {{ partial “bar.html” . }} in them too.

Here’s a sample project you can try:

git clone --single-branch -b hugo-forum-topic-39743 https://github.com/jmooring/hugo-testing hugo-forum-topic-39743
cd hugo-forum-topic-39743
hugo server

Thanks. Very nice. I am making some progress. One problem was that in my project there was no {{ define “main” }}{{ end }} in layouts/_default/{home,single}.html. With that I do indeed only get the content of the partial. Now I just need to find a way to do a second file with another partial.

Either parameterize the partial call based on a front matter value, or create another template and set the layout in front matter.

Yes, creating another template and using "Type: " in the .md files works nicely. Problem solved! Thanks again.

1 Like