Repository: gohugoio/hugo (language: go)

Issue:
Invoking .Page.RenderString on a page without a backing file throws an erroneous warning
This was introduced in v0.92.0, and is still present in v0.92.1. 

MRE:

```bash
git clone --single-branch -b hugo-github-issue-9433 https://github.com/jmooring/hugo-testing hugo-github-issue-9433
cd hugo-github-issue-9433
hugo 
```

> .File.Path on zero object. Wrap it in if or with: {{ with .File }}{{ .Path }}{{ end }}

The warning is triggered in layouts/_default/list.html, line 4:

```
{{ .RenderString "foo" }}
```

References:
- <https://discourse.gohugo.io/t/36590/5>
- <https://github.com/gohugoio/hugo/issues/9383#issuecomment-1013704831>


Discussion / hints:
Thanks ... We should have made that an error long time ago, but I guess we cannot do that in a patch release ...

Fix patch:
diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go
index 5581b6ebd95..dcbf1a6061f 100644
--- a/hugolib/page__meta.go
+++ b/hugolib/page__meta.go
@@ -768,16 +768,20 @@ func (p *pageMeta) newContentConverter(ps *pageState, markup string, renderingCo
 
 	var id string
 	var filename string
+	var path string
 	if !p.f.IsZero() {
 		id = p.f.UniqueID()
 		filename = p.f.Filename()
+		path = p.f.Path()
+	} else {
+		path = p.Pathc()
 	}
 
 	cpp, err := cp.New(
 		converter.DocumentContext{
 			Document:        newPageForRenderHook(ps),
 			DocumentID:      id,
-			DocumentName:    p.File().Path(),
+			DocumentName:    path,
 			Filename:        filename,
 			ConfigOverrides: renderingConfigOverrides,
 		},


Test patch:
diff --git a/hugolib/content_render_hooks_test.go b/hugolib/content_render_hooks_test.go
index f1c27d51191..edfeaa82a81 100644
--- a/hugolib/content_render_hooks_test.go
+++ b/hugolib/content_render_hooks_test.go
@@ -18,6 +18,7 @@ import (
 	"testing"
 
 	qt "github.com/frankban/quicktest"
+	"github.com/gohugoio/hugo/common/loggers"
 )
 
 func TestRenderHookEditNestedPartial(t *testing.T) {
@@ -484,3 +485,15 @@ func TestRenderStringOnListPage(t *testing.T) {
 		b.AssertFileContent("public/"+filename, `<strong>Hello</strong>`)
 	}
 }
+
+// Issue 9433
+func TestRenderStringOnPageNotBackedByAFile(t *testing.T) {
+	t.Parallel()
+	logger := loggers.NewWarningLogger()
+	b := newTestSitesBuilder(t).WithLogger(logger).WithConfigFile("toml", `
+disableKinds = ["page", "section", "taxonomy", "term"]	
+`)
+	b.WithTemplates("index.html", `{{ .RenderString "**Hello**" }}`).WithContent("p1.md", "")
+	b.BuildE(BuildCfg{})
+	b.Assert(int(logger.LogCounters().WarnCounter.Count()), qt.Equals, 0)
+}