safeHTMLAttr.md (805B)
1 --- 2 title: safeHTMLAttr 3 # linktitle: safeHTMLAttr 4 description: Declares the provided string as a safe HTML attribute. 5 date: 2017-02-01 6 publishdate: 2017-02-01 7 lastmod: 2017-02-01 8 categories: [functions] 9 menu: 10 docs: 11 parent: "functions" 12 keywords: [strings] 13 signature: ["safeHTMLAttr INPUT"] 14 workson: [] 15 hugoversion: 16 relatedfuncs: [] 17 deprecated: false 18 aliases: [] 19 --- 20 21 Example: Given a site-wide `config.toml` that contains this menu entry: 22 23 {{< code-toggle file="config" >}} 24 [[menu.main]] 25 name = "IRC: #golang at freenode" 26 url = "irc://irc.freenode.net/#golang" 27 {{< /code-toggle >}} 28 29 * <span class="bad">`<a href="{{ .URL }}">` → `<a href="#ZgotmplZ">`</span> 30 * <span class="good">`<a {{ printf "href=%q" .URL | safeHTMLAttr }}>` → `<a href="irc://irc.freenode.net/#golang">`</span>