Golang html/template.HTMLAttr type example
package html/template
HTMLAttr encapsulates an HTML attribute from a trusted source, for example,
dir="ltr"
.
Golang html/template.HTMLAttr type usage example
type navItem struct {
Name string
Attrs map[template.HTMLAttr]string
}
func activeNav(active string) []navItem {
// create menu items
about := navItem{
Name: "About",
Attrs: map[template.HTMLAttr]string{
"href": "/about",
"title": "About Page",
},
}
home := navItem{
Name: "Home",
Attrs: map[template.HTMLAttr]string{
"href": "/",
"title": "Home Page",
},
}
// set active menu class
switch active {
case "about":
about.Attrs["class"] = "active"
case "home":
home.Attrs["class"] = "active"
}
return []navItem{home, about}
}
References :
http://golang.org/pkg/html/template/#HTMLAttr
https://github.com/james-maloney/templates/blob/master/example/main.go
Advertisement
Something interesting
Tutorials
+10.3k Golang : Wait and sync.WaitGroup example
+10.4k Golang : Detect number of faces or vehicles in a photo
+17.1k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+7.5k Golang : How to detect if a sentence ends with a punctuation?
+13.8k Golang : Set image canvas or background to transparent
+26.7k Golang : Encrypt and decrypt data with AES crypto
+17.8k Convert JSON to CSV in Golang
+11.6k Use systeminfo to find out installed Windows Hotfix(s) or updates
+22.6k Golang : How to read JPG(JPEG), GIF and PNG files ?
+6.3k Golang : Get Hokkien(福建话)/Min-nan(閩南語) Pronounciations
+5.8k Javascript : How to refresh page with JQuery ?