From d71ed99d3bd96dd7bb0075bc9cc73ce6e9b31fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 1 Jul 2020 10:43:17 +0200 Subject: [PATCH] Add support for inline partials Fixes #7444 --- content/en/templates/partials.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/content/en/templates/partials.md b/content/en/templates/partials.md index 873f5e696..d23622ded 100644 --- a/content/en/templates/partials.md +++ b/content/en/templates/partials.md @@ -81,6 +81,21 @@ This means the partial will *only* be able to access those variables. The partia In addition to outputting markup, partials can be used to return a value of any type. In order to return a value, a partial must include a lone `return` statement. +## Inline partials + +{{< new-in "0.74.0" >}} + +You can also define partials inline in the template. But remember that template namespace is global, so you need to make sure that the names are unique to avoid conflicts. + +```go-html-template +Value: {{ partial "my-inline-partial" . }} + +{{ define "partials/my-inline-partial" }} +{{ $value := 32 }} +{{ return $value }} +{{ end }} +``` + ### Example GetFeatured ```go-html-template {{/* layouts/partials/GetFeatured.html */}}