func (t *Template) load() (*Template, error) {
	l := t.cfg.Name
	base := template.New(l).Funcs(Funcs)
	t.tpl = base
	var lerr error
	for _, dir := range t.cfg.IncludesDirs {
		for _, name := range asset.AssetNames() {
			if strings.HasPrefix(name, dir) {
				tpl := t.tpl.New(name)
				nd, err := asset.Asset(name)
				if err != nil {
					lerr = err
					break
				}
				_, err = tpl.Parse(string(nd))
				if err != nil {
					lerr = err
					break
				}
			}
		}
	}
	if lerr != nil {
		return nil, lerr
	}
	return t, nil
}
loads the templates, using constraints specified in the cfg provided at initialization.
The templates are read from the embedded assets, no extesion observation is made. The
global Funcs is used as the template funcmap.
package tmpl
import (
	"bytes"
	"fmt"
	"html/template"
	"io"
	"strings"
	"time"
	"github.com/zedio/zedlist/modules/db"
	"github.com/zedio/zedlist/modules/query"
	"github.com/labstack/echo"
	"github.com/Unknwon/com"
	asset "github.com/zedio/zedlist/bindata/template"
	"github.com/zedio/zedlist/models"
	"github.com/zedio/zedlist/modules/i18n"
	"github.com/zedio/zedlist/modules/log"
	"github.com/zedio/zedlist/modules/mdown"
)
const (
	LoginTpl = "auth/login.html"
	RegisterTpl = "auth/register.html"
	DeleteTpl = "auth/delete.html"
	JobsNewTpl = "jobs/new.html"
	JobsViewTpl = "jobs/view.html"
	JobsListTpl = "jobs/list.html"
	JobsUpdateTpl = "jobs/update.html"
	RegisterScripts = "/auth/date_picker.html"
	DashHomeTpl = "dash/home.html"
	DashJobTpl = "dash/jobs_new.html"
	DashProfileTpl = "dash/profile.html"
	ResumeNewTpl = "resume/new.html"
	ResumeHomeTpl = "resume/home.html"
	ResumeUpddateTpl = "resume/update.html"
	ResumeViewTpl = "resume/view.html"
	BaseHomeTpl = "base/home.html"
	BaseJobsHomeTpl = "base/jobs.html"
	BaseDocsHomeTpl = "base/docs_index.html"
	BaseDocTpl = "base/docs.html"
	BaseRegionsTpl = "base/regions.html"
	BaseRegionsJobViewTpl = "base/regions_job.html"
	BaseRegionsPaginateTpl = "base/regions_paginate.html"
	ErrNotFoundTpl = "errors/404.html"
	ErrServerTpl = "errors/500.html"
	ErrBadRequest = "errors/400.html"
)
var (
	NotFoundMessage = "we cant find the resource you asked for, please try again with different details"
	ServerErrorMessage = "Oops, there was a problem"
	BadRequestMessage = "bad request"
)
var TPL *Template
func init() {
	config := &Config{
		Name: "base",
		IncludesDirs: []string{
			"base",
			"partials",
			"auth",
			"dash",
			"errors",
			"resume",
			"jobs",
		},
	}
	t, err := New(config)
	if err != nil {
		log.Error(nil, err)
	}
	TPL = t
}
var Funcs = template.FuncMap{
	"date":       date,
	"tr":         translate,
	"md":         toMarkdown,
	"plain":      toHTML,
	"label":      label,
	"script":     script,
	"snake":      com.ToSnakeCase,
	"dashed":     dashed,
	"flag":       flagClass,
	"switchLang": switchLang,
	"username":   useername,
	"owner":      owner,
	"jobStats":   jobStats,
	"asJS":       asJS,
}
type Config struct {
	Name string
	IncludesDirs []string
}
type Template struct {
	cfg *Config
	tpl *template.Template
}
func New(cfg *Config) (*Template, error) {
	t := &Template{cfg: cfg}
	return t.load()
}
func (t *Template) Render(tpl string, val interface{}) (string, error) {
	out := &bytes.Buffer{}
	err := t.tpl.ExecuteTemplate(out, tpl, val)
	if err != nil {
		return "", err
	}
	return out.String(), nil
}
func (t *Template) RenderTo(out io.Writer, name string, data interface{}) error {
	err := t.tpl.ExecuteTemplate(out, name, data)
	if err != nil {
		log.Error(nil, err)
		return err
	}
	return nil
}