Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gschier/hagl
🧱 HTML templating in Go
https://github.com/gschier/hagl
golang html template-engine
Last synced: about 2 months ago
JSON representation
🧱 HTML templating in Go
- Host: GitHub
- URL: https://github.com/gschier/hagl
- Owner: gschier
- Created: 2020-06-07T06:39:11.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-11T23:39:49.000Z (6 months ago)
- Last Synced: 2024-10-10T05:38:07.256Z (2 months ago)
- Topics: golang, html, template-engine
- Language: Go
- Homepage:
- Size: 52.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# HAGL
HAGL (HTML Abstraction Go Library) is a Go library for rendering HTML, inspired
by [Elm](https://elm-lang.org).## Example
```go
package mainimport (
. "github.com/gschier/hagl"
)func main() {
loggedIn := trueheader := func() Node {
return H1().Text("Hello World!")
}root := Div().Children(
// Comments
Comment("This is a simple example"),// Composable elements
header().Class("hero"),// Looping
Ul().Range(3, func(i int) Node {
return Li().Textf("Item %d", i)
}),// Conditional rendering
Switch(loggedIn).
Case(true, func() Node {
return A().Attr("href", "/logout").Text("Logout")
}).
Default(func() Node {
return A().Attr("href", "/login").Text("Log In")
}),
)println(root.HTMLPretty())
}
``````html
```