Skip to main content

Template Project

Github StackBlitz

This project demonstrates how to set up a Go application with template rendering, Tailwind CSS, and Parcel for asset bundling.

Prerequisites

Ensure you have the following installed:

  • Golang
  • Node.js
  • npm

Setup

  1. Clone the repository:

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

    npm install

Usage

Building Assets

  1. Build the assets:

    npm run build
  2. Watch assets for changes:

    npm run dev

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 (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
)

func main() {
// Initialize the template engine
engine := html.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!",
})
})

// Start the server
app.Listen(":3000")
}

References