Documentation ¶
Index ¶
- Variables
- func NewRenderData(app *pocketbase.PocketBase) map[string]any
- func Render(r Renderable) (string, error)
- func RenderBlock(block string, data map[string]any) (string, error)
- func RenderEmail(t string, data map[string]any) (string, error)
- func RenderPage(t string, data map[string]any) (string, error)
- func RenderPageWithLayout(t string, layout string, data map[string]any) (string, error)
- type Renderable
Constants ¶
This section is empty.
Variables ¶
var InternalFiles embed.FS
var PublicFiles embed.FS
Functions ¶
func NewRenderData ¶
func NewRenderData(app *pocketbase.PocketBase) map[string]any
NewRenderData creates and returns a map containing render data for the given app. The render data includes the environment variable "WGA_ENV" and the contents of the "analytics.txt" file. If the "renderable:analytics" cache is not available, the file is read and stored in the cache. The "Analytics" key in the map contains the contents of the "analytics.txt" file.
func Render ¶
func Render(r Renderable) (string, error)
Render renders a Renderable object and returns the resulting HTML string. If the Renderable object is marked as htmx, it renders the block using RenderBlock. Otherwise, it renders the page using RenderPage.
func RenderBlock ¶
renderBlock renders a given block of HTML using the provided data and returns the resulting HTML string. The function searches for HTML templates in the "views/pages" and "views/partials" directories of the InternalFiles filesystem. It uses the utils.TemplateFuncs map to provide additional functions to the templates. If an error occurs while parsing or rendering the template, the function returns an empty string and the error.
func RenderEmail ¶
RenderEmail renders an email template with the given data. The function takes a string `t` representing the template name and a map `data` containing the data to be rendered. It returns a string representing the rendered email and an error if any occurred.
func RenderPage ¶
renderPage renders the given template with the provided data and returns the resulting HTML string. The template is parsed from the views directory using the provided template name and the layout.html file. If the template cannot be parsed or there is an error rendering it, an error is returned.