Standard library / html/template

html/template.Template.Lookup()

Finds an associated template by name; returns nil if it is not defined. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Template) Lookup(name string) *Template

Parameters & Attributes

NameTypeDescription
namestringName of the template.

Return Value

*Template

Finds an associated template by name; returns nil if it is not defined.

Working Example

Example Snippetgo
package main
import (  "fmt"  "html/template")
func main() {  t := template.Must(template.New("greet").Parse("Hello {{.}}"))  fmt.Println(t.Lookup("greet") != nil, t.Lookup("absent") == nil)}
Go Reference