mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
Merge commit 'f96384a3b596f9bc0a3a035970b09b2c601f0ccb'
This commit is contained in:
@@ -1,27 +1,20 @@
|
||||
---
|
||||
title: truncate
|
||||
# linktitle: truncate
|
||||
description: Truncates a text to a max length without cutting words or leaving unclosed HTML tags.
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
parent: functions
|
||||
keywords: [strings]
|
||||
signature:
|
||||
- "truncate SIZE [ELLIPSIS] INPUT"
|
||||
- "strings.Truncate SIZE [ELLIPSIS] INPUT"
|
||||
workson: []
|
||||
hugoversion: 19
|
||||
relatedfuncs: []
|
||||
deprecated: false
|
||||
---
|
||||
|
||||
Since Go templates are HTML-aware, `truncate` will intelligently handle normal strings vs HTML strings:
|
||||
|
||||
```
|
||||
```go-html-template
|
||||
{{ "<em>Keep my HTML</em>" | safeHTML | truncate 10 }}` → <em>Keep my …</em>`
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user