Two .Content sections in one markdown file?


#1

Is there a way to have two or more “Content” sections in the same markdown file?
.
Let’s say that for an ecommerce site each single page (template single.html) has two free text sections: one for the overall product description and one for the specifications.

Ideally, these two sections would be written in markdown language below the front matter of the .md file for that given page, and then called from single.html with something similar to {{ .Content }}. The issue is that {{.Content}} fetches everything below the front matter… Is it possible to separate that content of the .md file in two or more subsections of {{.Content}}?


#2

Currently no – but your use case may be solved in a nice way using a page bunde (seach the docs). Have a look at the showcase section in Hugo docs site for inspiration.


#3

Thanks for the reply bep.

Yes… I’ve noted the possibility of bundle several .md files together (using this feature for the images already), but it’d be probably leaner to have everything in the same .md file, and access it in a similar way as we can access the shortcodes with .Inner.

Do you know, if there’s a plan to implement such feature in future versions?

Cheers


#4

That feature is not planned, as page bundles gets the job done. :slight_smile:


#5

Not entirely correct. I have some plans in this department; I have talked about it elsewhere – on my TODO list is to update to Blackfriday 2, which should allow us to create a “content map” of sorts, which would be a tree of your content. The plans are a little bit vague, but the main point is to get a data structure with ToC and footnotes etc, but I assume this could be extended to “content sections”.


#6

What does that look like for a markdown file? Like, multiple --- sections, or a different way to markup “content” section in front matter?


#7

It currently does not look like anything. But the obvious first iteration would be to provide the headers as the sections, e.g.

{{ range .Content.Toc }}
{{ range .Content.Headers.H2 }}
{{ range .Content.Footnotes }}

But we could also imagine “custom annotations” to create sections, e.g.

{{range .Content.MySections }}

The above is very quickly made up for this post. But my ultimate goal is that you in a very speedy way should be able to traverse the content tree from file/directories and down to paragraph level in a speedy way.


#8

Just want to add there are many cool things that this would enable:

  • Insert an ad after every 5th (or something) paragraph
  • Insert author byline etc. after the summary
  • Present the ToC with any markup you want
  • Put the footnotes wherever you want
  • … insert your imaginary use cse here

#9

Content paragraph control in my use case would speed up image intensive projects that currently rely on shortcodes.

I have found out that too many shortcodes come with a price. Inserting images at the template level through a good old parameter or resources is always faster.

However the situation upstream with Blackfriday 2 and that other slow fork (that mmark now uses) is a bit like catch 22 and it doesn’t seem like the situation will change anytime soon.


#10

There is no catch 22. This is all about time and priority.