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
+4.9k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+8.4k Facebook : Getting the friends list with PHP return JSON format
+6.6k Gogland : Single File versus Go Application Run Configurations
+17.3k Golang : Padding data for encryption and un-padding data for decryption
+19.7k Golang : For loop continue,break and range
+13.3k Golang : Convert(cast) int to float example
+10.3k Golang : Generate DSA private, public key and PEM files example
+3.8k Python : Find out the variable type and determine the type with simple test
+42.6k Golang : Use wildcard patterns with filepath.Glob() example
+46.2k Golang : How to convert JSON string to map and slice
+5.7k Golang : Reverse by word
+40.5k Golang : Convert []byte to image