Detect if a more tag is in the markdown

Hey there,
Building my archive templates in my current project I will never use the default 70 words summary returned by default by Hugo.

Instead I will either use the front matters’ description OR whatever is before the <!--more--> tag. For this I need to test if the <!--more--> tag is present.

I assumed .Truncated would evaluate the presence of the <!--more--> but it does not, it seems to return true in any case which doesn’t make sense to me so apologies for I am obviously missing something.

I looked for the

That being said, is there any way to easily spot a <!--more--> tag in my content so I can choose between displaying whatever is before it, or in the case there are none, just the .Params.description ?

Thanks a ton!

Have a look at the split template function.

Example: Multiple Markdown-text-sections

Instead of "<split>" in that example, look for "<!--more-->".

It should be faster to use strings.Contains.

1 Like

Yes, of course… I misread the question… @regis needs to just test if that string is present, not extract the split elements…

Thank you both!
Still amazed by the reactivity of this community!

Cheers :slight_smile:

Just dropping the Go Template usage here (you should test .RawContent and not .Content):

{{ if strings.Contains .RawContent "<!--more-->" }}
	{{ .Summary }}
{{ else }}
	{{ .Description }}
{{ end }}
1 Like