- allows you to have layouts, pages, blocks (partials)
- allows you to live reload public files and templates in dev mode and use embeded files in production (golang's embed)
- allows you to render dynamically set blocks via 'd-block' instead of 'block'
- d-block allows you to use a headless-cms that serves json and assets only
- files
- public
- override.css
- hopefullynot.js
- templates
- layouts
- application.gohtml
- special.gohtml
- pages (must contain define 'page' - all of em, always 'page' - not 'todos_show' etc.)
- todos_show.gohtml
- todos_index.gohtml
- todos_edit.gohtml
- ...
- blocks (definition within file must start with _ and must contain definition '_form')
- form.gohtml
- message.gohtml
- layouts
- public
import echo_integration "github.com/templates/integrations/echo"
...
// (embeded) public files and templates
fileSystem := getFileSystem("files", in_dev_mode)
templates := templates.New(fileSystem, "./templates", nil)
templates.AlwaysReloadAndParseTemplates = in_dev_mode
templates.MustParseTemplates()
// sample echo
e := echo.New()
e.Pre(echo_integration.MethodOverrideFormField("_method"))
e.Use(echo_integration.CSRFTokenLookup("form:csrf"))
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Renderer = echo_integration.Renderer(templates)
func (ht *Handlers) Todos(c echo.Context) error {
...
return c.Render(200, "todos_index", data) // renders page with default layout 'application'
// or
return c.Render(200, "special:todos_index", data) // renders the page with the 'special' layout
// or
return c.Render(200, ":todos_index", data) // renders the page without a layout
// or
return c.Render(200, "_message", data) // renders only the block/partial/snippet/... without a page or layout
// without echo
templates.ExecuteTemplate(respone, request, "_message or as above", data)
}
{{block "_sample_block_with_locals" locals "a" 1 "b" 2 "c" 3 }}{{end}}
{{locals "a" "x" "b" "y" "c" "z" | d_block "_sample_block_with_locals" }}
[x] use safehtml instead of std lib [x] move integrations_echo to seperate package [ ] code cleanup [ ] implement sse for hotwired turbo [ ] add tests for hotwired turbo