Skip to main content

Template Project

Github StackBlitz

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

  1. Clone the repository:

    git clone https://github.com/gofiber/recipes.git
    cd recipes/template
  2. Install dependencies:

    go get

Running the Application

  1. 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"))
}

References