Two div sections one markdown file

Here’s one approach…

markdown:

+++
title = "Test"
date = 2020-08-22T07:02:03-04:00
draft = false
+++
This is the content for the **first** section.
<!-- section break -->
This is the content for the **second** section.

layouts/_default/single.html:

{{ define "main" }}
  <h1>{{ .Title }}</h1>

  {{- $sectionDelimiter := "<!-- section break -->" -}}
  {{- $rawContentSections := split .RawContent $sectionDelimiter -}}
  {{- if gt (len $rawContentSections) 1 -}}
    <div id="section-1">
      {{ index $rawContentSections 0 | .RenderString }}
    </div>
    <div id="section-2">
      {{ index $rawContentSections 1 | .RenderString }}
    </div>
  {{- else -}}
    <div id="content-not-split-into-sections">
      {{ .Content }}
    </div>
  {{- end -}}

{{ end }}
6 Likes