Closed tsiamer closed 2 years ago
Hey @Siamert, thanks for the question.
Have you tried moving the {{ $tag }}
out of the range block? Seems like this would fix that for you. Eg. something like...
{{range services}}
{{range $tag, $services := service .Name | byTag }}
{{if or (eq $tag "Volkswagen") }}
{{ $tag}}
{{ range $services }}
{{ .Name }}
{{ end }}{{ end }}{{end}}{{end}}
Hope this helps!
Hi Eikenb,
Thank for the reply, same output i am getting:
Volkswagen
Golf
Volkswagen
BUW
Sorry, I thought that inner range was the one with multiple entries instead of the middle one. That will take a different approach.
How something like this one? ...
{{- range $tag,$srv := services | byTag }}
{{ if (ne \$tag "Volkswagen") }}{{continue}}{{end}}
{{ \$tag }}:
{{- range $srv }}
{{ .Name -}}
{{ end }}{{ end }}
Thank you it is not working getting below error, but it gives an idea to start with. parse: template: :2: function "continue" not defined
Hmm... I see I accidentally left in some escapes, eg. the \
in \$tag
. Remove those and it should work (or see below). Sorry about that.
{{- range $tag,$srv := services | byTag }}
{{ if (ne $tag "Volkswagen") }}{{continue}}{{end}}
{{ $tag }}:
{{- range $srv }}
{{ .Name -}}
{{ end }}{{ end }}
Hmm... I see I accidentally left in some escapes, eg. the
\
in\$tag
. Remove those and it should work (or see below). Sorry about that.{{- range $tag,$srv := services | byTag }} {{ if (ne $tag "Volkswagen") }}{{continue}}{{end}} {{ $tag }}: {{- range $srv }} {{ .Name -}} {{ end }}{{ end }}
Working thank you John.
Glad I could help.
If in the future you have a question and I'm not able to answer it for some reason (work priorities or whatever) remember to try using our discuss forum as it has more eyes on it than these github issues and you may get more help, faster.
Good luck!
Please note that the Consul Template issue tracker is reserved for bug reports and enhancements. For general usage questions, please use the Consul Community Portal or the Consul mailing list:
Please try to simplify the issue as much as possible and include all the details to replicate it. The shorter and simpler the bug is to reproduce the quicker it can be addressed. Thanks.
Consul Template version
Run
consul-template -v
to show the version. If you are not running the latest version, please upgrade before submitting an issue.consul-template v0.29.0 (34ada7a)
Configuration:
I would like to group consul service by tags, using the below:
Output:
I d like it to be:
Volkswagen is the tag:
Thanks