Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 981 Bytes

README.md

File metadata and controls

56 lines (44 loc) · 981 Bytes

Util 🧩 Templates

Use html/template Out of the Box

Usage :

Import it to your code 🔠

    import (
        alfTemplates "github.com/PiterWeb/Alf-Router/utils/templates"
    )

Use it on your custom Routes

// main.go

    useTemplate := alfTemplates.Templates("./templatesFolder", ".go.html")

    err := alf.App(&alf.AppConfig{
    	Port: "3000",
    	Routes: alf.CreateRouter([]alf.Route{
    		{
				Path: "/",
				Handle: func(ctx *alf.Ctx) error {
					return useTemplate(ctx, "index", "I am a Text")
				},
				Method: "get",
			},
    	}),
    })

    if err != nil {
		panic(err)
	}
<!-- /templatesFolder/index.go.html -->

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <h1>Hello World</h1>

        <h2>Text from go: {{.}}</h2>
    </body>
</html>