Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 main

import (
. "github.com/gschier/hagl"
)

func main() {
loggedIn := true

header := 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



Hello World!



  • Item 0

  • Item 1

  • Item 2


Logout

```