yaml
Serializes a value as YAML, so a map assembled in a template can be written out as a config file or a manifest.
It ships as a stub that returns an error until you inject a codec. Which YAML library to bind, and with which options, is a choice that belongs to the application rather than to this package, and the core stays free of third-party dependencies by not making it for you. Injecting one is a map entry.
func marshalYAML(v any) (string, error) {
out, err := yaml.Marshal(v)
return string(out), err
}
mods := serialize.Modifiers()
mods[string(serialize.ModifierNameYAML)] = functions.Wrap(marshalYAML)
out, err := sintax.New(mods).Render(tpl, vars)It takes any value rather than only a string, since anything renderable is serializable.
anyno argumentsstringSerializes a map as YAML once a codec is injected, so a map assembled in a template can be written out as a config file.
Given
{"config": {"host": "localhost", "port": 8080}}Template
{{ config | yaml }}Result
host: localhost
port: 8080Shows what the modifier does before a codec is bound. The stub errors rather than guessing a format, so a missing injection surfaces at render time instead of silently emitting nothing.
Given
{"config": {"host": "localhost"}}Template
{{ config | yaml }}Result
error: failed to render template: failed to render variable token 'config': modifier "yaml": function failed to apply: yaml function needs to be injected