Dynamic page with content from different files

I appreciate this has been requested several times already, but I still believe there is not a full solution on it.

So simple question.

GIVEN a page created in /content/ to be rendered on disk
AND several page chunks in the say /content/page-chunks folder

How can I have the main page injecting HTML content with rendered template tags to be rendered
AND avoid intermediate files to be written/accessible on disk?

So far, following the hints here, I have tried the following approaches:

  1. files in the /assets, can successfully imported using the resources.get along with an ExecuteasTemplate to render the template tags, but they don’t to execute the shortcodes.
    It doesn’t matter whether extension is .html or .md or whether there is a frontmatter (even if empty)
  2. files in /content/ can be imported with a ReadFile and SafeHTML but no chances to get templateTags and shortcodes working
  3. Partials, but here the files have to be in the /partials folder which to me should not logically contains any form of content.

Do you guys have another solution?

Thanks for your hints.

Hi there,

By “page chunks” do you mean page content in markdown files?

Have a look at this page in the docs: Build Options | Hugo

And also this one: Page Bundles | Hugo

If these don’t answer your questions, you can make it easier to get help by linking to your sample code showing your site structure and what you’ve tried that doesn’t work. Please also have a read about Requesting Help

1 Like

Thanks for the hints.

Build send to be the one I need, but I can’t figure out why pages are not returned?
A print is returning a nil.

Pages have been moved into /content/home/*.
So I now have

  • /content/en/home/box1
  • /content/en/home/box2

The above en folder is part of the localisation settings.

But when pages are accessed via {{ with site.GetPage “/home/box1” }}
But also trying with the leading slash or the full path, doesn’t give results.

As an attempt, I tried to ignore the localisation part completely moving the content in the root, without tangible results.
Am I missing something obvious?

Your file schema is a bit limited. Is this content/en/home/box1.md And is there any other file in the content/en/home/ directory?

If you have a /content/en/home/index.md then this is a Page Bundle, this means box1.md and box2.md are not stand alone pages but Pages Resource of /content/en/home/index.md.

So you need to access them from the “home” page object with .Resources.Get "box1". Then you can print their .Content just like any other page’s and the shortcode will work.

Hi @regis
no, my content/en/home does not contain any index.md file. Just the “boxes” files which I’m trying to render from a located in /layouts/_default/test.html

But just in case, I’ve tried also to replicate the example in the doc, with events file and a <h1>{{ with .Site.GetPage "section" "events" }}{{ .Title }}{{ end }}</h1>.
Even in this circumstance nothing is printed.

Silly question. Do the .md files need to contain both a Frontmatter and content?
Say something like this

date: 2012-04-15
title: event1

Silly question. Do the .md files need to contain both a Frontmatter and content?
Say something like this


this is a bit confusing to me. Do you have a repo to share?

Not online … I’m just playing around locally. So what does the box1.md or event1.md need to contain?

It’s not clear from this page.

Just an amendment … re the frontmatter … I tried to copy paste also what was in the page as

title: Who we are
 list: false
 render: false

But no chances

I’m not sure why you say no… I’ve re-read the documentation and the build options are in fact shaping a normal markdown file behaviour, helping to get it rendered on the disk and/or hidden in the hierarchy tree.

Re-looking at the content tree and picking the proper path, I was in the end able to get the POC done, but I still noticed that while the content is now rendered in the page, if the markdown contains a {{ tag }} e.g. (T sometranslation), the tag is interpreted and escaped in HTML.

Here note that I have to change the setting to render the markdown settings in the config.yaml file to markup: goldmark: renderer: unsafe: true to get the .md content being printed.

The only way I’ve seen tags being executed is using shortcodes, but again when they are rendered, HTML is escaped and does not do what is expected (I see <pre><code> being added everywhere)

I really appreciate your advice.

I would highly recommend creating a free github account and uploading the contents of your hugo folder to share so you can ask specific questions and get feedback on the code and structures you have created.

1 Like

You asked if md files needed to contain both Front Matter and Body/Content. This answer is no. Only Front Matter, Content is optional.

1 Like