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.8k Golang : Command line file upload program to server example
+6k Golang : Experimenting with the Rejang script
+9.1k Golang : Handle sub domain with Gin
+18k Golang : Get all upper case or lower case characters from string example
+9.7k Golang : Find correlation coefficient example
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+9.2k Golang : Create and shuffle deck of cards example
+8.4k Golang : Generate Datamatrix barcode
+7.7k Golang : How to execute code at certain day, hour and minute?
+48.1k Golang : How to convert JSON string to map and slice
+5.3k Golang : Get FX sentiment from website example
+11.3k Golang : Byte format example