NewTemplate returns a new template intended to be evaluated with this context, as it is initialized with configuration from this context.
(tplName string)
| 60 | // NewTemplate returns a new template intended to be evaluated with this |
| 61 | // context, as it is initialized with configuration from this context. |
| 62 | func (c *TemplateContext) NewTemplate(tplName string) *template.Template { |
| 63 | c.tpl = template.New(tplName).Option("missingkey=zero") |
| 64 | |
| 65 | // customize delimiters, if applicable |
| 66 | if c.config != nil && len(c.config.Delimiters) == 2 { |
| 67 | c.tpl.Delims(c.config.Delimiters[0], c.config.Delimiters[1]) |
| 68 | } |
| 69 | |
| 70 | // add sprig library |
| 71 | c.tpl.Funcs(sprigFuncMap) |
| 72 | |
| 73 | // add all custom functions |
| 74 | for _, funcMap := range c.CustomFuncs { |
| 75 | c.tpl.Funcs(funcMap) |
| 76 | } |
| 77 | |
| 78 | // add our own library |
| 79 | c.tpl.Funcs(template.FuncMap{ |
| 80 | "include": c.funcInclude, |
| 81 | "readFile": c.funcReadFile, |
| 82 | "import": c.funcImport, |
| 83 | "httpInclude": c.funcHTTPInclude, |
| 84 | "stripHTML": c.funcStripHTML, |
| 85 | "markdown": c.funcMarkdown, |
| 86 | "splitFrontMatter": c.funcSplitFrontMatter, |
| 87 | "listFiles": c.funcListFiles, |
| 88 | "fileStat": c.funcFileStat, |
| 89 | "env": c.funcEnv, |
| 90 | "placeholder": c.funcPlaceholder, |
| 91 | "ph": c.funcPlaceholder, // shortcut |
| 92 | "fileExists": c.funcFileExists, |
| 93 | "httpError": c.funcHTTPError, |
| 94 | "humanize": c.funcHumanize, |
| 95 | "maybe": c.funcMaybe, |
| 96 | "pathEscape": url.PathEscape, |
| 97 | }) |
| 98 | return c.tpl |
| 99 | } |
| 100 | |
| 101 | // OriginalReq returns the original, unmodified, un-rewritten request as |
| 102 | // it originally came in over the wire. |