Skip to content
/ hagl Public

🧱 HTML templating in Go

Notifications You must be signed in to change notification settings

gschier/hagl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HAGL

HAGL (HTML Abstraction Go Library) is a Go library for rendering HTML, inspired by Elm.

Example

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())
}
<div>
  <!-- This is a simple example -->
  <h1 class="hero">Hello World!</h1>
  <ul>
    <li>Item 0</li>
    <li>Item 1</li>
    <li>Item 2</li>
  </ul>
  <a href="/logout">Logout</a>
</div>

About

🧱 HTML templating in Go

Topics

Resources

Stars

Watchers

Forks

Languages