Search code examples
go-templates

How to use continue and break keywords in golang templates?


For example:

{{range .Users}}
    {{if .IsAdmin}}
        {{/* How to use "break" or "continue"? */}}
    {{end}}
{{end}}

The documentation for "break" or "continue" in templates is not available in golang.org


Solution

  • They are not documented because they do not exist.

    To make sure - check the tests for the text/template lexer: https://github.com/golang/go/blob/master/src/text/template/parse/lex_test.go