Adding custom template functions #3239
AurelPaulovic
started this conversation in
General
Replies: 1 comment
-
It looks like I need the functionality of tmpl := html_template.New(te.name)
tmpl.Funcs(html_template.FuncMap{
"tmpl": func(name string, data interface{}) (html_template.HTML, error) {
var buffer bytes.Buffer
err := tmpl.ExecuteTemplate(&buffer, name, data)
return html_template.HTML(buffer.String()), err
},
}) Having |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I would like to ask if Alertmanager supports adding custom template functions to alerting templates without having to create a custom build of the Alertmanager codebase. The problem is that Go templates and the functions provided in the alerting templates are very restrictive. Even if I could define some "function" as as a nested template, Go templates don't allow me to assign the output of the nested template into a variable within another template or use in conditionals so there is no way for me to reuse code.
I imagine I could solve my problems if there was a way for me to dynamically define custom template functions or evaluate template within variable assignment or conditionals, i.e. something like non-existing function
callNestedTemplate
:I found #3174 which looks promising and at least adds support at the level of
template.FromGlobs
by supplyingOption
. However, it still seems that there is no way to use this with standard build of Alertmanager using some form of plugin.Beta Was this translation helpful? Give feedback.
All reactions