Skip to content

proposal: text/template, html/template: add LookupFunc, LookupOption methodsΒ #43062

@jba

Description

@jba

It is possible using only exported symbols to write a type-checker for templates. There is just one missing piece: to check a function call like {{len .}}, the checker needs the function signature, but there is no way to retrieve that from a Template.

To work around this, I copied the information for built-ins from text/template, and I must ask the user to pass to my checker whatever FuncMaps they used when parsing the template. The first solution is brittle and the second unpleasant.

All that is missing is the method Template.LookupFunc(name string) interface{}. It would behave much like the unexported findFunction function in text/template/funcs.go, but it would return the unreflected function value or nil if the name was undefined.

I propose it be added to both text/template.Template and html/template.Template.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions