template

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package template manages templates including creation, retrieval and rendering.

Index

Constants

View Source
const (
	// Built-in templates names stored in the database.
	TmplConversationAssigned = "Conversation assigned"
	TmplSLABreachWarning     = "SLA breach warning"
	TmplSLABreached          = "SLA breached"
	TmplMentioned            = "Mentioned in conversation"

	// Built-in templates fetched from memory stored in `static` directory.
	TmplResetPassword = "reset-password"
	TmplWelcome       = "welcome"

	// Template names for rendering.
	TmplBase    = "base"
	TmplContent = "content"
)

Variables

View Source
var (
	ErrTemplateNotFound   = errors.New("template not found")
	TypeEmailOutgoing     = "email_outgoing"
	TypeEmailNotification = "email_notification"
)

Functions

This section is empty.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles template-related operations.

func New

func New(lo *logf.Logger, db *sqlx.DB, webTpls *template.Template, tpls *template.Template, funcMap template.FuncMap, i18n *i18n.I18n) (*Manager, error)

New creates and returns a new instance of the Manager.

func (*Manager) Create

func (m *Manager) Create(t models.Template) (models.Template, error)

Create creates a template.

func (*Manager) Delete

func (m *Manager) Delete(id int) error

Delete deletes a template by id.

func (*Manager) Get

func (m *Manager) Get(id int) (models.Template, error)

Get returns a template by id.

func (*Manager) GetAll

func (m *Manager) GetAll(typ string) ([]models.Template, error)

GetAll returns all templates by type.

func (*Manager) Reload

func (m *Manager) Reload(webTpls, tpls *template.Template, funcMap template.FuncMap) error

Reload reloads the templates and function map.

func (*Manager) RenderEmailWithTemplate

func (m *Manager) RenderEmailWithTemplate(data any, content string) (string, error)

RenderEmailWithTemplate renders content inside the default outgoing email template.

func (*Manager) RenderInMemoryTemplate

func (m *Manager) RenderInMemoryTemplate(name string, data interface{}) (string, error)

RenderInMemoryTemplate executes an in-memory template with data and returns the rendered content. This is for system emails like reset password and welcome email etc.

func (*Manager) RenderStoredEmailTemplate

func (m *Manager) RenderStoredEmailTemplate(name string, data any) (string, string, error)

RenderStoredEmailTemplate fetches and renders an email template from the database, including subject and body and returns the rendered content.

func (*Manager) RenderWebPage

func (m *Manager) RenderWebPage(ctx *fasthttp.RequestCtx, tmplFile string, data map[string]interface{}) error

RenderWebPage renders a template to the http.ResponseWriter with data.

func (*Manager) Update

func (m *Manager) Update(id int, t models.Template) (models.Template, error)

Update updates a new template with the given name, and body.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL