Help us shape the future of Go! Take the 2026 Go Developer Survey

render

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package render provides Pine's built-in HTML template engine.

Call Setup once after creating a server to install the engine and, when Config.ReloadTemplates is true, start automatic hot-reloading:

app := pine.New(pine.Config{ViewPath: "views", ReloadTemplates: true})
if err := render.Setup(app); err != nil {
    log.Fatal(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LiveReload

func LiveReload(server *pine.Server, engine *Engine) error

LiveReload wires up template hot-reloading for development.

It registers a WebSocket endpoint at "/__pine_reload" that browser clients connect to. A file watcher (powered by websocket.Watch) monitors server.ViewPath() for template changes. On each change it:

  1. Calls engine.Rebuild() to re-parse all templates on the server side.
  2. Broadcasts a "reload" frame to every connected browser tab.

Engine.Render() detects that live reload is active and automatically injects a tiny inline <script> into every HTML response — no template changes needed.

LiveReload is called automatically by Setup() when server.ReloadTemplates() is true — there is no need to call it explicitly.

func Setup

func Setup(server *pine.Server) error

Setup installs the HTML engine on server and, when server.ReloadTemplates() is true, also starts live reload. This is the single entry point for configuring rendering in a Pine application.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is Pine's HTML template engine. It implements pine.ViewEngine and pine.Reloader using Go's html/template package. All fields are safe for concurrent use.

func New

func New(viewPath string) (*Engine, error)

New creates and returns a new Engine pre-loaded with all templates found under viewPath. Supported extensions: .html, .gohtml, .tmpl. Each template is named by its path relative to viewPath with forward-slash separators, e.g. "index.html" or "admin/dashboard.html".

func (*Engine) Rebuild

func (e *Engine) Rebuild() error

Rebuild re-parses all template files from disk and atomically swaps the template set. Called by LiveReload on every detected file change.

func (*Engine) Render

func (e *Engine) Render(w io.Writer, name string, data interface{}) error

Render executes the named template and writes the result to w. When live reload is active it also appends the hot-reload <script> tag so that browsers reconnect automatically after every save.

Jump to

Keyboard shortcuts

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