templates

package
v0.0.0-...-8d3c269 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 2 Imported by: 0

README

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>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Templates

func Templates(templatesFolder string, extension string) func(ctx *alf.Ctx, templateName string, data any) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL