Hi all,
I’ve been reading posts about adding multiple markdown files to a single page.
For example:
Etc.
The reason for wanting this is usually for home pages or landing pages and the like.
What about if we allow markdown content in data files? Then we can iterate over data files like we normally do for everything else, we can grab the content and markdownify it, but the files are not rendered elsewhere in the site (rather hacky).
This seems an easy fix and much more elegant. WDYT?
P.s. this assumes that I am correct in thinking that you can’t have content in data files.
content1 = """
##This is a header for content 1
And some more **content**...
"""
content2 = """
##This is a header for content 2
And some more content...
"""
And then in your template:
{{ .Site.Data.home.content1 | markdownify }}
Note:
The markdownify func behaves “better” in the next Hugo (aka current development version)
There are also several open issues/plan to improve this “multiple content for one page” scenario. It will happen, eventually.
Yeah ok, that’s what I’m doing at the moment. I would have thought it made more sense to do this in the datafile (which would be more consistent with “normal” pages):
---
title: Hi there
---
This is my _markdown_ content.
Which then begs the question, why do we need data files when we could just use pages (with an option to prevent them being published maybe?). But I’ll leave that for another day.
A content file can only have 1 .Content, which, if I understand you correctly, is the foundation of your question? So if you want to put several “content sections” in the home page you can use a data file to pull in content for those sections.
Yes, a content file can only have one .Content. That is fine. But I don’t want to use content pages (like others have) to construct single pages (like a home page) because I don’t want to have to faff around stopping the content pages creating html pages in their own right.
Hence, data files are a better solution for me, but I just wish I could add .Content to data files without having to write them in the front-matter.