github.com/rabbouni145/gg@v0.47.1/docs/content/en/functions/truncate.md (about) 1 --- 2 title: truncate 3 # linktitle: truncate 4 description: Truncates a text to a max length without cutting words or leaving unclosed HTML tags. 5 godocref: 6 date: 2017-02-01 7 publishdate: 2017-02-01 8 lastmod: 2017-02-01 9 categories: [functions] 10 menu: 11 docs: 12 parent: "functions" 13 keywords: [strings] 14 signature: ["truncate SIZE INPUT", "truncate SIZE ELLIPSIS INPUT"] 15 workson: [] 16 hugoversion: 19 17 relatedfuncs: [] 18 deprecated: false 19 --- 20 21 Since Go templates are HTML-aware, `truncate` will intelligently handle normal strings vs HTML strings: 22 23 ``` 24 {{ "<em>Keep my HTML</em>" | safeHTML | truncate 10 }}` → <em>Keep my …</em>` 25 ``` 26 27 {{% note %}} 28 If you have a raw string that contains HTML tags you want to remain treated as HTML, you will need to convert the string to HTML using the [`safeHTML` template function](/functions/safehtml) before sending the value to truncate. Otherwise, the HTML tags will be escaped when passed through the `truncate` function. 29 {{% /note %}}