| 1 |
--- |
| 2 |
title: transform.HTMLEscape |
| 3 |
description: Returns the given string, escaping special characters by replacing them with HTML entities. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [htmlEscape] |
| 9 |
returnType: string |
| 10 |
signatures: [transform.HTMLEscape INPUT] |
| 11 |
aliases: [/functions/htmlescape] |
| 12 |
--- |
| 13 |
|
| 14 |
The `transform.HTMLEscape` function escapes five special characters by replacing them with [HTML entities][]: |
| 15 |
|
| 16 |
- `&` → `&` |
| 17 |
- `<` → `<` |
| 18 |
- `>` → `>` |
| 19 |
- `'` → `'` |
| 20 |
- `"` → `"` |
| 21 |
|
| 22 |
For example: |
| 23 |
|
| 24 |
```go-html-template |
| 25 |
{{ htmlEscape "Lilo & Stitch" }} → Lilo & Stitch |
| 26 |
{{ htmlEscape "7 > 6" }} → 7 > 6 |
| 27 |
``` |
| 28 |
|
| 29 |
[HTML entities]: https://developer.mozilla.org/en-US/docs/Glossary/Entity |