Irritating "unrecognized character" when nothing of the sort is visible

I have a really, really annoying problem and I don’t know if it’s text editor or hugo. I wrote this line:

{{ .Getpage “docs”}}

There are two leading spaces after the ̀{{`.
Like this I get:

Error: “/home/drm/WEBSITE/layouts/partials/docs/menu.html:25:1”: parse failed: template: partials/docs/menu.html:25: unrecognized character in action: U+00A0

And when I edit out the first leading character, I get:

Error: “/home/drm/WEBSITE/layouts/partials/docs/menu.html:25:1”: parse failed: template: partials/docs/menu.html:25: unrecognized character in action: U+FFFD ‘�’

Then I undo the change, and the first message doesn’t come back. Of course, neither unicode characters are present at the start of the line. I tried editing it in nano too, same issue, so it might not be micro after all. Is the parser bugging ?

Version: hugo v0.123.7-312735366b20d64bd61bff8627f593749f86c964+extended linux/amd64 BuildDate=2024-03-01T16:16:06Z VendorInfo=gohugoio
Same happens with 0.122.0

You seem to have an error in menu.html

Do share the repo to understand the issue.

Yes… don’t get mad because of google drive please.
https://drive.google.com/drive/folders/1Pax07_jZ-d6vPCuSdWp-sVz51T2ax02B?usp=sharing

menu.html does have an unidentifed character.
You need to fix it to:
{{.Getpage "docs"}}

Then the same file has an erronous call on line 50 as:

{{ range $context1 := (.GetPage "docs").Pages }}

You can’t use .GetPage here. You should rather use:

{{ where .Site.RegularPages "Section" "docs" }}

When this is fixed another error pops up in the file on line 60.

Do you really have curly quotes in your code or is that just some artifact?

Why not?

artifact. I’m not seeing any or if that’s what you mean. Or am I mistaken ? I certainly wouldn’t introduce them willfully.
Ok, I replaced my context declaration by yours, which I prefer anyway. But it seems its main merit (because mine worked for @jmooring) was to make the error message clearer:

Error: error building site: render: failed to render pages: render of "page" failed: "/home/drm/WEBSITE/layouts/_default/baseof.html:10:40": execute of template failed: template: 
_default/single.html:10:40: executing "menu-block" at <partial "docs/menu" .>: error calling partial:
"/home/drm/WEBSITE/layouts/partials/docs/menu.html:49:23": execute of template failed: template: 
partials/docs/menu.html:49:23: executing "menu-filetree" at <where .Site.RegularPages "Section" "docs">:
error calling where: can't iterate over <nil>

So even though the pages within the sections are published all right… the sections aren’t counted among .Site.RegularPages "Section" "docs"

(btw this unrecognized character issue is no longer relevant, eventhough we still dunno what caused it. can we fused the last posts with Template code can't iterate the filetree as before - #14 by jmooring ?)

Its presence showed error.
Do you think the syntax is correct ?

Both constructs below are fine…

{{ range (site.GetPage "/docs").Pages }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
{{ range where site.RegularPages "Section" "docs" }}
  <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}

…but they render different page collections.

1 Like

Ok, which one iterates over the content of “docs”, so that I can iterate over the content’s content ?

/content/docs
├──􀀂 Biology … (pages)
├──􀀂 History … (pages)
└──􀀂 Love …(pages)

https://gohugo.io/quick-reference/page-collections/

Ok, I see it’s getting nowhere. I’ll rewrite that template from 0. No clue why it worked for you but not for me or others, who cares :roll_eyes:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.