| 1 |
--- |
| 2 |
title: end |
| 3 |
description: Terminates if, with, range, block, and define statements. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [] |
| 9 |
returnType: |
| 10 |
signatures: [end] |
| 11 |
--- |
| 12 |
|
| 13 |
Use with the [`if`][] statement: |
| 14 |
|
| 15 |
```go-html-template |
| 16 |
{{ $var := "foo" }} |
| 17 |
{{ if $var }} |
| 18 |
{{ $var }} → foo |
| 19 |
{{ end }} |
| 20 |
``` |
| 21 |
|
| 22 |
Use with the [`with`][] statement: |
| 23 |
|
| 24 |
```go-html-template |
| 25 |
{{ $var := "foo" }} |
| 26 |
{{ with $var }} |
| 27 |
{{ . }} → foo |
| 28 |
{{ end }} |
| 29 |
``` |
| 30 |
|
| 31 |
Use with the [`range`][] statement: |
| 32 |
|
| 33 |
```go-html-template |
| 34 |
{{ $var := slice 1 2 3 }} |
| 35 |
{{ range $var }} |
| 36 |
{{ . }} → 1 2 3 |
| 37 |
{{ end }} |
| 38 |
``` |
| 39 |
|
| 40 |
Use with the [`block`][] statement: |
| 41 |
|
| 42 |
```go-html-template |
| 43 |
{{ block "main" . }}{{ end }} |
| 44 |
``` |
| 45 |
|
| 46 |
Use with the [`define`][] statement: |
| 47 |
|
| 48 |
```go-html-template |
| 49 |
{{ define "main" }} |
| 50 |
{{ print "this is the main section" }} |
| 51 |
{{ end }} |
| 52 |
``` |
| 53 |
|
| 54 |
{{% include "/_common/functions/go-template/text-template.md" %}} |
| 55 |
|
| 56 |
[`block`]: /functions/go-template/block/ |
| 57 |
[`define`]: /functions/go-template/define/ |
| 58 |
[`if`]: /functions/go-template/if/ |
| 59 |
[`range`]: /functions/go-template/range/ |
| 60 |
[`with`]: /functions/go-template/with/ |