Template Project
This project demonstrates how to set up a Go application with template rendering using the Django template engine.
Prerequisites
Ensure you have the following installed:
- Golang
Setup
-
Clone the repository:
git clone https://github.com/gofiber/recipes.gitcd recipes/template -
Install dependencies:
go get
Running the Application
- Start the Fiber application:
go run main.go
Example
Here is an example of how to set up a basic route with template rendering in Go:
package main
import (
"log"
"github.com/gofiber/fiber/v3"
"github.com/gofiber/template/django/v4"
)
func main() {
// Initialize the template engine
engine := django.New("./views", ".html")
// Create a new Fiber instance with the template engine
app := fiber.New(fiber.Config{
Views: engine,
})
// Define a route
app.Get("/", func(c fiber.Ctx) error {
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
log.Fatal(app.Listen(":3000"))
}