1
0
Fork 0
mirror of https://github.com/gohugoio/hugo.git synced 2025-03-31 10:55:04 +00:00
hugo/docs/content/en/methods/page/Truncated.md
2024-11-13 11:07:57 +01:00

955 B

title description categories keywords action
Truncated Reports whether the content length exceeds the summary length.
related returnType signatures
methods/page/Summary
bool
PAGE.Truncated

You can define a summary manually, in front matter, or automatically. A manual summary takes precedence over a front matter summary, and a front matter summary takes precedence over an automatic summary.

The Truncated method returns true if the content length exceeds the summary length. This is useful for conditionally rendering a "read more" link:

{{ range .Pages }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
  {{ .Summary }}
  {{ if .Truncated }}
    <a href="{{ .RelPermalink }}">Read more...</a>
  {{ end }}
{{ end }}

{{% note %}} The Truncated method returns false if you define the summary in front matter. {{% /note %}}