tpl: Narrow down the usage of plain text shortcodes when rendering HTML

After this commit, if you want to resolve `layouts/_shortcodes/myshortcode.txt` when rendering HTML content, you need to use the `{{%` shortcode delimiter:

```
{{% myshortcode %}}
```

This should be what people would do anyway, but we have also as part of this improved the error message to inform about what needs to be done.

Note that this is not relevant for partials.

Fixes #13698
This commit is contained in:
Bjørn Erik Pedersen
2025-05-16 10:36:05 +02:00
parent 6142bc701c
commit 61317821e4
6 changed files with 127 additions and 24 deletions

View File

@@ -920,6 +920,26 @@ func TestPartialHTML(t *testing.T) {
b.AssertFileContent("public/index.html", "<link rel=\"stylesheet\" href=\"/css/style.css\">")
}
func TestPartialPlainTextInHTML(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
-- layouts/all.html --
<html>
<head>
{{ partial "mypartial.txt" . }}
</head>
</html>
-- layouts/partials/mypartial.txt --
My <div>partial</div>.
`
b := hugolib.Test(t, files)
b.AssertFileContent("public/index.html", "My &lt;div&gt;partial&lt;/div&gt;.")
}
// Issue #13593.
func TestGoatAndNoGoat(t *testing.T) {
t.Parallel()
@@ -1103,6 +1123,18 @@ All.
b.AssertLogContains("unrecognized render hook")
}
func TestLayoutNotFound(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
-- layouts/single.html --
Single.
`
b := hugolib.Test(t, files, hugolib.TestOptWarn())
b.AssertLogContains("WARN found no layout file for \"html\" for kind \"home\"")
}
func TestLayoutOverrideThemeWhenThemeOnOldFormatIssue13715(t *testing.T) {
t.Parallel()
@@ -1214,8 +1246,8 @@ s2.
Category: tplimpl.CategoryShortcode,
Desc: desc,
}
v := store.LookupShortcode(q)
if v == nil {
v, err := store.LookupShortcode(q)
if v == nil || err != nil {
b.Fatal("not found")
}
}