.Summary, .Content and the rest

Hi,

we’re using .Summary and .Content a lot. Basically, we show the .Summary on an overview page and if the user clicks on the link he gets the .Content to read the full article. That’s great. However, we have some writers who also write pages and we want to use the .Summary as the lead to the text. The lead is formatted differently than the rest of the text. So, what we now try to achieve is using the .Summary to be formatted as lead (different CSS) and the rest as the standard body.

The problem is that the .Summary works fine, but if we then add the .Content it also holds the already shown .Summary. Is there a way to strip the .Summary from the .Content so that we get the rest only?

This is what we want:

<h1> {{ .Title }}</h1>
<p class="lead"> {{ .Summary }} </p>
<p class="body"> {{ .Content.withoutSummary }}</p>

Any ideas?

Thanks!

Interesting question. Haven’t tested this, but maybe this would work:

{{ substr .Content (len .Summary) }}
1 Like

I suspected some hacks would arrive in this thread. And they may work … This is on my list of improvements I want in Hugo, but should be done properly in the Markdown parser. I have suggested creating a “content section map” …

Your particular use case is discussed here:

2 Likes
<h1> {{ .Title }}</h1>
<p class="lead"> {{ .Summary }} </p>
<p class="body"> {{ .Content.withoutSummary }}</p>

@bep Is there developed any solution for this example ?

From the thread that bep listed, this looks like a usable workaround:

{{ $body := replace .Content .Summary "" }}
{{ $body | safeHTML }}

You would add the summary in its own styled div above this.

@TotallyInformation :+1: thanks, it works perfectly