mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
tpl: Add docshelper for template funcs
And fix some other minor related issues. Updates #3418
This commit is contained in:
@@ -24,21 +24,27 @@ func init() {
|
||||
f := func(d *deps.Deps) *internal.TemplateFuncsNamespace {
|
||||
ctx := New()
|
||||
|
||||
examples := [][2]string{
|
||||
{`{{ "1234" | int | printf "%T" }}`, `int`},
|
||||
{`{{ 1234 | string | printf "%T" }}`, `string`},
|
||||
}
|
||||
|
||||
return &internal.TemplateFuncsNamespace{
|
||||
ns := &internal.TemplateFuncsNamespace{
|
||||
Name: name,
|
||||
Context: func() interface{} { return ctx },
|
||||
Aliases: map[string]interface{}{
|
||||
"int": ctx.ToInt,
|
||||
"string": ctx.ToString,
|
||||
},
|
||||
Examples: examples,
|
||||
}
|
||||
|
||||
ns.AddMethodMapping(ctx.ToInt,
|
||||
[]string{"int"},
|
||||
[][2]string{
|
||||
{`{{ "1234" | int | printf "%T" }}`, `int`},
|
||||
},
|
||||
)
|
||||
|
||||
ns.AddMethodMapping(ctx.ToString,
|
||||
[]string{"string"},
|
||||
[][2]string{
|
||||
{`{{ 1234 | string | printf "%T" }}`, `string`},
|
||||
},
|
||||
)
|
||||
|
||||
return ns
|
||||
|
||||
}
|
||||
|
||||
internal.AddTemplateFuncsNamespace(f)
|
||||
|
Reference in New Issue
Block a user