MCPcopy Create free account
hub / github.com/unrolled/render / layoutFuncs

Method layoutFuncs

render.go:410–449  ·  view source on GitHub ↗
(templates *template.Template, name string, binding interface{})

Source from the content-addressed store, hash-verified

408}
409
410func (r *Render) layoutFuncs(templates *template.Template, name string, binding interface{}) template.FuncMap {
411 return template.FuncMap{
412 "yield": func() (template.HTML, error) {
413 buf, err := r.execute(templates, name, binding)
414
415 // Return safe HTML here since we are rendering our own template.
416 return template.HTML(buf.String()), err
417 },
418 "current": func() (string, error) {
419 return name, nil
420 },
421 "block": func(partialName string) (template.HTML, error) {
422 log.Println("Render's `block` implementation is now depericated. Use `partial` as a drop in replacement.")
423 fullPartialName := fmt.Sprintf("%s-%s", partialName, name)
424 if templates.Lookup(fullPartialName) == nil && r.opt.RenderPartialsWithoutPrefix {
425 fullPartialName = partialName
426 }
427 if r.opt.RequireBlocks || templates.Lookup(fullPartialName) != nil {
428 buf, err := r.execute(templates, fullPartialName, binding)
429 // Return safe HTML here since we are rendering our own template.
430 return template.HTML(buf.String()), err
431 }
432
433 return "", nil
434 },
435 "partial": func(partialName string) (template.HTML, error) {
436 fullPartialName := fmt.Sprintf("%s-%s", partialName, name)
437 if templates.Lookup(fullPartialName) == nil && r.opt.RenderPartialsWithoutPrefix {
438 fullPartialName = partialName
439 }
440 if r.opt.RequirePartials || templates.Lookup(fullPartialName) != nil {
441 buf, err := r.execute(templates, fullPartialName, binding)
442 // Return safe HTML here since we are rendering our own template.
443 return template.HTML(buf.String()), err
444 }
445
446 return "", nil
447 },
448 }
449}
450
451func (r *Render) prepareHTMLOptions(htmlOpt []HTMLOptions) HTMLOptions {
452 layout := r.opt.Layout

Callers 1

HTMLMethod · 0.95

Calls 3

executeMethod · 0.95
HTMLMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected