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
+28.3k Golang : Connect to database (MySQL/MariaDB) server
+5k Python : Convert(cast) bytes to string example
+29.3k Golang : missing Git command
+16.8k Golang : Get own process identifier
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+10.3k Golang : How to get quoted string into another string?
+15.7k Golang : Force download file example
+7.9k Golang : Reverse a string with unicode
+40.7k Golang : Convert to io.ReadSeeker type
+11.7k Android Studio : Create custom icons for your application example
+12.4k Golang : Display list of countries and ISO codes
+8k Javascript : How to check a browser's Do Not Track status?