mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-10-04 11:56:02 -04:00
750 B
750 B
title | linktitle | description | godocref | date | publishdate | lastmod | categories | tags | toc | draft | aliases | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
truncate | truncate | 2017-02-01 | 2017-02-01 | 2017-02-01 |
|
false | false |
Truncate a text to a max length without cutting words or leaving unclosed HTML tags. Since Go templates are HTML-aware, truncate will handle normal strings vs HTML strings intelligently. It's important to note that if you have a raw string that contains HTML tags that you want treated as HTML, you will need to convert the string to HTML using the safeHTML template function before sending the value to truncate; otherwise, the HTML tags will be escaped by truncate.
{{ "<em>Keep my HTML</em>" | safeHTML | truncate 10 }}
→ <em>Keep my …</em>