How to check the summary divider presence


How to check if the article contains the summary divider (<!--more-->)?

I want to achieve the following. If an article contains the summary divider, then .Summary should show only the content before the divider (that already works just fine). And if there is no summary divider in the article, then there should be the full article content. The use case for that is short articles with only a couple of paragraphs of text.

I am thinking about something like this:

<ul class="posts-list">
  {{ range $index, $element := .Paginator.Pages }}
    <li class="posts-list-item">
      <a class="posts-list-item-title" href="{{ .Permalink }}">{{ .Title }}</a>

      <!-- here's the condition -->
      {{ if (isset .Page "summaryDivider") }}
        <p>{{ .Summary }}</p>
        <a class="link-readmore" href="{{ .RelPermalink }}">Read more</a>
      {{ else }}
        <p>{{ .Content }}</p>
      {{ end }}

  {{ end }}

Which of course doesn’t work as there is no such parameter as summaryDivider, so is there a parameter that can I use instead?

Or perhaps there is some other way to achieve what I want?


Hi there. Try something like:

{{ if in .RawContent "<!--more-->" }}
  // do something 
{{ else }}
  // do something else 
{{ end }}