Embedding multiple pieces of Markdown content in a template with page bundles

I have this structure:

├── compare
│   └── alternative1
│       ├── index.md
│       └── lead.md

and this template:

├── [_default etc]
├── compare
│   └── single.html

The compare/single.html template has a common structure for multiple leaf bundles - for example alternative1.

I want to include lead.md which is different for each page bundle. In compare/single.html I do:

<p class="lead">
{{ with .Resources.Get "lead.md" }}
{{ .Content }}
{{ end }}

I thought that would simply render the content. But instead, it renders it wrapped with <p> tags, so styles associated with the <p class="lead"> I defined in the template are overridden. I want the power of Markdown wrapping in each of these content files, but I don’t want it wrapped in a <p>.

This seems such a basic function I think I’m approaching this incorrectly. So if you can make alternative suggestions, please do so. Are page bundles the way to do this?

What do you mean by “wrapped in <p> tags?”

Can you provide an example of the “lead.md” content? And, does that file have front matter?

1 Like

Thanks for replying.

lead.md is just something like:

lorem ipsum

However I want it to potentially be something like:

lorem ipsum

**lorem** ipsum

lorem [ipsum](https://example.com/link)

(i.e. a multiline or single line markdown file)

I’ve tried it with and without empty front matter, but I’m not sure what front matter to use if it needs some.

I guess the issue is that the above will generate with <p> around each paragraph, and a one line piece of content where I don’t want that is a special case. This is why I think I’m approaching this wrong. How does one embed pieces of varying Markdown content for each bundle?

A single line of markdown is a paragraph, and will be wrapped within a p element.

Two lines of markdown is two paragraphs, and each will be wrapped within a p element.

Both are the correct behavior per the CommonMark spec.

If your file had only one line, you could do:

{{ with .Resources.Get "lead.md" }}
  {{ .RawContent | $.RenderString (dict "display" "inline") }}
{{ end }}

but not with multiple lines.

1 Like

You’re right, I wasn’t thinking this through correctly for all cases. I guess I need to be mindful of the tags wrapped around these imports - and to define more of a schema of the data that each bundle presents (e.g. maybe it’s invalid to provide markdown for this particular block of content if it’s going to be wrapped in a <p>).

I’m not sure exactly what you are doing, but you might consider using html files instead of md files to augment the content in some places.

├── compare/
│   └── alternative1/
│       ├── index.md
│       └── lead.html
└── _index.md


This is <strong>strong</strong> text.

This is more <strong>strong</strong> text.


{{ with .Resources.Get "lead.html" }}
  {{ .Content }}
{{ end }}
1 Like

Thanks. I prefer the Markdown syntax where possible but I can see that HTML might be better for some situations. I’ll see how it goes.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.