From b856d60b817f86f50b3613657580840ea1019c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 26 May 2023 12:46:44 +0200 Subject: [PATCH] demo: Demonstrate a way to control execution flow from e.g. single.html to the base template See #11023 --- hugolib/config_test.go | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/hugolib/config_test.go b/hugolib/config_test.go index 2f9c6e3f6..d5d98540b 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -1040,3 +1040,60 @@ HTACCESS. b.AssertFileContent("public/.htaccess", "HTACCESS") } + +func TestBaseSignalChildParent(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +-- content/_index.md -- +-- content/p1.md -- +-- layouts/_default/baseof.html -- +{{ block "_baseof_start" . }}{{ end }} + + +{{/* Lots of imports of SEO partials, stylesheets, JS and whatnot. */}} + + +{{ $flow := .Store.Get "_baseof_flow" | default "default" }} +{{ if eq $flow "default" }} +
+

Default flow

+ {{ block "main" . }}{{ end }} +
+{{ else if eq $flow "foo" }} +
+

Foo flow

+ {{ block "main" . }}{{ end }} +
+{{ else if eq $flow "bar" }} +
+

Bar flow

+ {{ block "main" . }}{{ end }} +
+{{ end }} + + +-- layouts/index.html -- +{{ define "_baseof_start" }}{{ .Page.Store.Set "_baseof_flow" "foo" }}{{ end }} +{{ define "main" }}Main Home{{ end }} +-- layouts/_default/single.html -- +{{ define "_baseof_start" }}{{ .Page.Store.Set "_baseof_flow" "bar" }}{{ end }} +{{ define "main" }}Main Single{{ end }} + + +` + b := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ).Build() + + b.AssertFileContent("public/index.html", ` +Foo flow +Main Home + +`) + +}