Documentation
¶
Overview ¶
Package htmlengine is an Ambient plugin that provides a HTML template engine.
Index ¶
- type Engine
- func (te *Engine) Body(t *template.Template, content string, fm template.FuncMap, ...) (*template.Template, error)
- func (te *Engine) Error(w http.ResponseWriter, r *http.Request, content string, statusCode int, ...) (err error)
- func (te *Engine) Footer(t *template.Template, content string, fm template.FuncMap, ...) (*template.Template, error)
- func (te *Engine) Head(t *template.Template, content string, fm template.FuncMap, ...) (*template.Template, error)
- func (te *Engine) Header(t *template.Template, content string, fm template.FuncMap, ...) (*template.Template, error)
- func (te *Engine) Main(t *template.Template, content string, fm template.FuncMap, ...) (*template.Template, error)
- func (te *Engine) Page(w http.ResponseWriter, r *http.Request, assets ambient.FileSystemReader, ...) (err error)
- func (te *Engine) PageContent(w http.ResponseWriter, r *http.Request, content string, ...) (err error)
- func (te *Engine) Post(w http.ResponseWriter, r *http.Request, assets ambient.FileSystemReader, ...) (err error)
- func (te *Engine) PostContent(w http.ResponseWriter, r *http.Request, content string, ...) (err error)
- type Plugin
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine represents a HTML template engine.
func NewTemplateEngine ¶
func NewTemplateEngine(logger ambient.Logger, assetInjector ambient.AssetInjector) *Engine
NewTemplateEngine returns a HTML template engine.
func (*Engine) Body ¶
func (te *Engine) Body(t *template.Template, content string, fm template.FuncMap, data map[string]interface{}) (*template.Template, error)
Body -
func (*Engine) Error ¶
func (te *Engine) Error(w http.ResponseWriter, r *http.Request, content string, statusCode int, fm func(r *http.Request) template.FuncMap, vars map[string]interface{}) (err error)
Error renders HTML to a response writer and returns a 404 status code and an error if one occurs.
func (*Engine) Footer ¶
func (te *Engine) Footer(t *template.Template, content string, fm template.FuncMap, data map[string]interface{}) (*template.Template, error)
Footer -
func (*Engine) Head ¶
func (te *Engine) Head(t *template.Template, content string, fm template.FuncMap, data map[string]interface{}) (*template.Template, error)
Head -
func (*Engine) Header ¶
func (te *Engine) Header(t *template.Template, content string, fm template.FuncMap, data map[string]interface{}) (*template.Template, error)
Header -
func (*Engine) Main ¶
func (te *Engine) Main(t *template.Template, content string, fm template.FuncMap, data map[string]interface{}) (*template.Template, error)
Main -
func (*Engine) Page ¶
func (te *Engine) Page(w http.ResponseWriter, r *http.Request, assets ambient.FileSystemReader, partialTemplate string, fm func(r *http.Request) template.FuncMap, vars map[string]interface{}) (err error)
Page renders using the page layout.
func (*Engine) PageContent ¶
func (te *Engine) PageContent(w http.ResponseWriter, r *http.Request, content string, fm func(r *http.Request) template.FuncMap, vars map[string]interface{}) (err error)
PageContent renders using the page content.
type Plugin ¶
type Plugin struct{}
Plugin represents an Ambient plugin.
func New ¶
func New() *Plugin
New returns an Ambient plugin that provides a HTML template engine.
Example ¶
package main
import (
"log"
"github.com/ambientkit/ambient"
"github.com/ambientkit/ambient/pkg/ambientapp"
"github.com/ambientkit/plugin/logger/zaplogger"
"github.com/ambientkit/plugin/storage/memorystorage"
"github.com/ambientkit/plugin/templateengine/htmlengine"
)
func main() {
plugins := &ambient.PluginLoader{
// Core plugins are implicitly trusted.
Router: nil,
TemplateEngine: htmlengine.New(),
SessionManager: nil,
// Trusted plugins are those that are typically needed to boot so they
// will be enabled and given full access.
TrustedPlugins: map[string]bool{},
Plugins: []ambient.Plugin{},
Middleware: []ambient.MiddlewarePlugin{
// Middleware - executes top to bottom.
},
}
_, _, err := ambientapp.NewApp("myapp", "1.0",
zaplogger.New(),
ambient.StoragePluginGroup{
Storage: memorystorage.New(),
},
plugins)
if err != nil {
log.Fatalln(err.Error())
}
}
func (*Plugin) PluginName ¶
PluginName returns the plugin name.
func (*Plugin) PluginVersion ¶
PluginVersion returns the plugin version.
func (*Plugin) TemplateEngine ¶
func (p *Plugin) TemplateEngine(logger ambient.Logger, injector ambient.AssetInjector) (ambient.Renderer, error)
TemplateEngine returns a template engine.
Click to show internal directories.
Click to hide internal directories.