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

@ -398,6 +398,10 @@ func doRenderShortcode(
return true
}
base, layoutDescriptor := po.GetInternalTemplateBasePathAndDescriptor()
// With shortcodes/mymarkdown.md (only), this allows {{% mymarkdown %}} when rendering HTML,
// but will not resolve any template when doing {{< mymarkdown >}}.
layoutDescriptor.AlwaysAllowPlainText = sc.doMarkup
q := tplimpl.TemplateQuery{
Path: base,
Name: sc.name,
@ -405,10 +409,9 @@ func doRenderShortcode(
Desc: layoutDescriptor,
Consider: include,
}
v := s.TemplateStore.LookupShortcode(q)
v, err := s.TemplateStore.LookupShortcode(q)
if v == nil {
s.Log.Errorf("Unable to locate template for shortcode %q in page %q", sc.name, p.File().Path())
return zeroShortcode, nil
return zeroShortcode, err
}
tmpl = v
hasVariants = hasVariants || len(ofCount) > 1