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>