MCPcopy Create free account
hub / github.com/kataras/iris / parseTemplate

Method parseTemplate

view/html.go:329–359  ·  view source on GitHub ↗
(name string, contents []byte, funcs template.FuncMap)

Source from the content-addressed store, hash-verified

327}
328
329func (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
361func (s *HTMLEngine) initRootTmpl() { // protected by the caller.
362 if s.Templates == nil {

Callers 3

loadMethod · 0.95
reloadCustomTemplatesMethod · 0.95
ParseTemplateMethod · 0.95

Calls 7

initRootTmplMethod · 0.95
getBuiltinFuncsMethod · 0.95
NewMethod · 0.80
OptionMethod · 0.80
ContainsMethod · 0.80
ParseMethod · 0.65
FuncsMethod · 0.45

Tested by

no test coverage detected