Check if .Content contains a string

How do I check if the post .Content contains a certain string? I am have tried the following code and none of them work.

  • Using in
{{ if in .Content "<!--more-->"}}
  <span>MORE!!!</span>
{{else}}
  <span>NO MORE!!!</span>
{{end}}
  • Using strings.Contains (Any reason this function is not listed in the documentation)
{{ if strings.Contains .Content "<!--more-->"}}
  <span>MORE!!!</span>
{{else}}
  <span>NO MORE!!!</span>
{{end}}

Both options end up in NO MORE!!! :frowning:

What am I missing?

.Content is the result of rendering the markdown to HTML. When that occurs, HTML comments are removed.

You need to perform your check against the content before it is rendered to HTML.

{{ if in .RawContent "<!--more-->" }}
  ...
{{ end }}
2 Likes

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