Standard library / text/template
text/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) *TemplateParameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Name 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" "text/template")
func main() { t := template.Must(template.New("greet").Parse("Hello {{.}}")) fmt.Println(t.Lookup("greet") != nil, t.Lookup("absent") == nil)}