Split markdown content in two .content <sections> (and: don't put them inside p tags)

In my response to 32080 (which I edited just now) I inadvertently omitted the p tags wrapping the section break, so you should do something like this instead:

layouts/_default/single.html
{{ $sectionBreak := "<p>[SECTION-BREAK]</p>" }}
{{ $sections := split .Content $sectionBreak }}

{{ if eq (len $sections) 1 }}
  {{ .Content }}
{{ else }}
  {{ range $k, $v := $sections }}
    {{ $id := printf "section-%d" (add 1 $k) }}
    <div id="{{ $id }}">
      {{ $v | strings.TrimSpace | safeHTML }}
    </div>
  {{ end }}
{{ end }}

Try it:

git clone --single-branch -b hugo-forum-topic-54148 https://github.com/jmooring/hugo-testing hugo-forum-topic-54148
cd hugo-forum-topic-54148
hugo server

If this doesn’t resolve your issue, please provide a Mardkown example.

1 Like