using-html-template

command
v1.42.4 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

README

Using HTML Template

This GoFr example demonstrates the use of html template, GoFr supports both static and dynamic html templates. All template files—whether HTML or HTMX—should be placed inside a templates directory located at the root of your project.

Usage
// path to the static html files
app.AddStaticFiles("/", "./static")

func listHandler(*gofr.Context) (any, error) {
	// Get data from somewhere
	data := TodoPageData{
		PageTitle: "My TODO list",
		Todos: []Todo{
			{Title: "Expand on Gofr documentation ", Done: false},
			{Title: "Add more examples", Done: true},
			{Title: "Write some articles", Done: false},
		},
	}
    // provide data and template name to response.Template 
	return response.Template{Data: data, Name: "todo.html"}, nil
}
To run the example use the command below:
go run main.go

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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