(name string, contents []byte, funcs template.FuncMap)
| 327 | } |
| 328 | |
| 329 | func (s *HTMLEngine) parseTemplate(name string, contents []byte, funcs template.FuncMap) (err error) { |
| 330 | s.initRootTmpl() |
| 331 | |
| 332 | name = strings.TrimPrefix(name, "/") |
| 333 | tmpl := s.Templates.New(name) |
| 334 | // tmpl.Option("missingkey=error") |
| 335 | tmpl.Option(s.options...) |
| 336 | |
| 337 | var text string |
| 338 | |
| 339 | if s.middleware != nil { |
| 340 | text, err = s.middleware(name, contents) |
| 341 | if err != nil { |
| 342 | return |
| 343 | } |
| 344 | } else { |
| 345 | text = string(contents) |
| 346 | } |
| 347 | |
| 348 | tmpl.Funcs(s.getBuiltinFuncs(name)).Funcs(s.funcs) |
| 349 | |
| 350 | if strings.Contains(name, "layout") { |
| 351 | tmpl.Funcs(s.layoutFuncs) |
| 352 | } |
| 353 | |
| 354 | if len(funcs) > 0 { |
| 355 | tmpl.Funcs(funcs) // custom for this template. |
| 356 | } |
| 357 | _, err = tmpl.Parse(text) |
| 358 | return |
| 359 | } |
| 360 | |
| 361 | func (s *HTMLEngine) initRootTmpl() { // protected by the caller. |
| 362 | if s.Templates == nil { |
no test coverage detected