mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-14 17:34:50 -04:00
Improve safeHTMLAttr explanation
This commit is contained in:
parent
b64cbce2ec
commit
5091bf6a0f
@ -34,12 +34,16 @@ Will produce:
|
||||
|
||||
`ZgotmplZ` is a special value, inserted by Go's [template/html] package, that indicates that unsafe content reached a CSS or URL context.
|
||||
|
||||
To override the safety check, use the `safeHTMLAttr` function:
|
||||
To indicate that the HTML attribute is safe:
|
||||
|
||||
```go-html-template
|
||||
{{ range site.Menus.main }}
|
||||
<a {{ printf "href=%q" .URL | safeHTMLAttr }}>{{ .Name }}</a>
|
||||
{{ end }}
|
||||
```
|
||||
```
|
||||
|
||||
{{% note %}}
|
||||
As demonstrated above, you must pass the HTML attribute name _and_ value through the function. Applying `safeHTMLAttr` to the attribute value has no effect.
|
||||
{{% /note %}}
|
||||
|
||||
[template/html]: https://pkg.go.dev/html/template
|
||||
|
Loading…
x
Reference in New Issue
Block a user