Skip to content
Template Management

Template Management

Template Management stores templates as projects of files which administrators can edit at runtime. It separates texts and layouts from code, for example the mails of Mail Management, and renders Go templates as plain text or HTML, or PDF documents with Typst.

Template projects

Enable

templates := std.Must(cfg.TemplateManagement()) // application.TemplateManagement

Template Management is always enabled, because Mail Management depends on it. It has the fields UseCases template.UseCases and Pages uitemplate.Pages with the paths Projects, NewProject and Editor.

Render a template

The configurator renders a named template of a project into a string, as the given subject:

text, err := cfg.TemplateString(subject, projectID, "body", model)

Execute renders a whole project and returns a reader. Localized files below locales/<language>/ override the default files for ExecOptions.Language. The execution type of a project decides the output:

Exec typeOutput
TreeTemplatePlaintext, Go text/template
TreeTemplateHTMLHTML; files ending in .gohtml are escaped
TypstPDFPDF, requires the typst binary on PATH
Unprocessedthe files as a zip

LatexPDF and AsciidocPDF are declared, but currently also rendered with Typst.

template.Apply(subject, fsys, execType, opts) renders templates from an fs.FS of your code without the system, e.g. embedded Typst files.

Ship default templates with your application with EnsureBuildIn, which creates a project if it does not exist yet.

Use cases

Use caseDescription
FindAllLists the projects readable by the subject, filtered by tags.
FindByIDLoads a project.
ExecuteRenders a project.
FSExecuteRenders templates from an fs.FS provided by code.
Create, DeleteCreate or delete a project.
EnsureBuildInCreates a built-in project if it does not exist.
LoadProjectBlob, CreateProjectBlob, UpdateProjectBlob, RenameProjectBlob, DeleteProjectBlobManage the files of a project.
AddRunConfiguration, RemoveRunConfigurationManage example models for previews.
ExportZip, ImportZipExport or import a project as a zip.

Permissions

PermissionAllows to
nago.template.find_alllist templates
nago.template.find_by_idview a template
nago.template.executerender templates
nago.template.createcreate projects
nago.template.deletedelete projects
nago.template.ensure_build_increate built-in projects
nago.template.project.blob.loadview project files
nago.template.project.blob.createcreate project files
nago.template.project.blob.updateupdate project files
nago.template.project.blob.renamerename project files
nago.template.project.blob.deletedelete project files
nago.template.project.runcfg.addadd run configurations
nago.template.project.runcfg.removeremove run configurations
nago.template.project.exportexport projects
nago.template.project.importimport projects

UI

admin/template/projects lists the projects, optionally filtered with ?tag=, admin/template/new creates one and admin/template/edit edits its files. The admin center shows the cards E-Mail Vorlagen, PDF Vorlagen and Alle Vorlagen in the group Vorlagen & Templates.

Related