76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
// Package template provides a high-performance template engine with in-memory
|
|
// caching, automatic reloading, and advanced template composition features.
|
|
//
|
|
// # Basic Usage
|
|
//
|
|
// cache := template.NewCache("") // Auto-detects binary location
|
|
// tmpl, err := cache.Load("page.html")
|
|
// if err != nil {
|
|
// log.Fatal(err)
|
|
// }
|
|
//
|
|
// data := map[string]any{
|
|
// "title": "Welcome",
|
|
// "user": map[string]any{
|
|
// "name": "Alice",
|
|
// "email": "alice@example.com",
|
|
// },
|
|
// }
|
|
//
|
|
// result := tmpl.RenderNamed(data)
|
|
//
|
|
// # Placeholder Types
|
|
//
|
|
// Named placeholders: {name}, {title}
|
|
//
|
|
// Dot notation: {user.name}, {user.contact.email}
|
|
//
|
|
// Positional: {0}, {1}, {2}
|
|
//
|
|
// # Template Composition
|
|
//
|
|
// Includes - embed other templates with data sharing:
|
|
//
|
|
// {include "header.html"}
|
|
// {include "nav.html"}
|
|
//
|
|
// Blocks - define reusable content sections:
|
|
//
|
|
// {block "content"}
|
|
// <h1>Default content</h1>
|
|
// {/block}
|
|
//
|
|
// Yield - template inheritance points:
|
|
//
|
|
// <main>{yield content}</main>
|
|
// <footer>{yield footer}</footer>
|
|
//
|
|
// # Template Inheritance Example
|
|
//
|
|
// layout.html:
|
|
//
|
|
// <!DOCTYPE html>
|
|
// <html>
|
|
// <head><title>{title}</title></head>
|
|
// <body>{yield content}</body>
|
|
// </html>
|
|
//
|
|
// page.html:
|
|
//
|
|
// {include "layout.html"}
|
|
// {block "content"}
|
|
// <h1>Welcome {user.name}!</h1>
|
|
// {/block}
|
|
//
|
|
// # Advanced Features
|
|
//
|
|
// Disable includes for partial rendering:
|
|
//
|
|
// opts := RenderOptions{ResolveIncludes: false}
|
|
// chunk := tmpl.RenderNamedWithOptions(opts, data)
|
|
//
|
|
// FastHTTP integration:
|
|
//
|
|
// tmpl.WriteTo(ctx, data) // Sets content-type and writes response
|
|
package template
|