mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-06 02:36:21 +03:00
Merge commit 'ec4e6f9df2
' as 'docs'
This commit is contained in:
commit
a1900826b9
839 changed files with 44703 additions and 0 deletions
29
docs/content/functions/truncate.md
Normal file
29
docs/content/functions/truncate.md
Normal file
|
@ -0,0 +1,29 @@
|
|||
---
|
||||
title: truncate
|
||||
# linktitle: truncate
|
||||
description: Truncates a text to a max length without cutting words or leaving unclosed HTML tags.
|
||||
godocref:
|
||||
date: 2017-02-01
|
||||
publishdate: 2017-02-01
|
||||
lastmod: 2017-02-01
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: "functions"
|
||||
#tags: [strings]
|
||||
signature: ["truncate SIZE INPUT", "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:
|
||||
|
||||
```
|
||||
{{ "<em>Keep my HTML</em>" | safeHTML | truncate 10 }}` → <em>Keep my …</em>`
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
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.
|
||||
{{% /note %}}
|
Loading…
Add table
Add a link
Reference in a new issue