templated

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2020 License: BSD-4-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package templated implements a lightweight mail templating mechanism.

Store your templates in dir "A", then Render will execute "A/base/index.html" as the main template for the mail body, adding any other files in "A/base" as helper templates, stylesheets, images etc. Other subfolders of "A", e.g. "A/en_US" should contain one file per templated message. These files should define 2 templates: "subject" and "body" (using the {{ define 'name"}} ... {{end}} syntax).

See the tests and the "example" folder for a demonstration.

Example
cnf := Config{"example", "en_US"}
ctx := map[string]interface{}{
	"Name":    "Test Customer",
	"Company": "ACME Coorp",
}

subj, body, err := Render(&cnf, "foo", ctx)
if err != nil {
	fmt.Println(err)
}
fmt.Printf("Subject: %s\n", string(subj))
fmt.Printf("Body:\n%s\n", string(body))
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(c *Config, name string, data interface{}) (string, []byte, error)

Render renders the template c.Dir/c.Lang/name in the context of c.Dir/base/index.html.

See the tests and the "example" folder for a demonstration.

Types

type Config

type Config struct {
	// Dir is the directory where your templates live. It's supposed to have a
	// subfolder named "base" in which the Render method will look for the main and
	// helper templates.
	Dir string

	// Lang names the language subfolder of Dir in which the file containing
	// the message specific templates named "subject" and "body" are located.
	Lang string
}

Config helps you to manage your templates.

Jump to

Keyboard shortcuts

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