[solved] ERROR with baseof template: "unrecognized character"

Hello all,

I have a template baseof.html with the following block:

{{ block "main" . }}<p>Hello World!</p>{{ end }}

In my index.html I define as follows:

{{ define "main" }}<p>Hello Homepage!</p>{{ end }}

This seems correct to me but Hugo exits with an error:

`/layouts/index.html:5: unexpected unrecognized character in action: U+00A0 in command``

I have tried hours trying to debug this including this steps:

  • delete index.html and write it new from ground up with placeholder content (as above)
  • trying other editors including nano (my default editor is sublime text)
  • removing spaces (e.g. writing {{define “main”}} )
  • altering basof.html

and so on … I can’t seem to find the reason for the error :frowning:
EDIT: means I can’t find the offending non-breaking space.

Any help is greatly appreciated!

Hugo Static Site Generator v0.20.7 darwin/amd64 BuildDate: 2017-05-04T11:18:37+02:00

You have a no-break space character inside a template command, in line 5 of index.html.

hello bep, thank’s for your reply, but no, I can’t find any non-breaking spaces in my template. actually there is only one (1) line left in the template (the one posted above) …

before posting for help i’ve started from scratch, deleted my index.html and wrote the above posted single line to strip it down to the bare minimum thus avoiding any unwanted spaces. same result.

this is what’s driving me nuts. i can’t find any nbsp’s :frowning:

The thing is,

  1. I’m pretty sure the error is accurate
  2. I’m not sure how we could help you without seeing the FULL source of the failing site.

Hi bep,

many thanks again for trying to help me. While collecting the source files for this post i found the offending line: it was line 5 of baseof.html and it wasn’t a block definition but a partial call I’ve copied and pasted from the docs (together with the non-breaking space presumably). It’s running now.

However, still not sure why Hugo complains about index.html while the offending line is in basof.html? Assume lookup order is the reason?

Next time I’ll post the full source code from the beginning.

It is a little bit misleading, I agree, but the /layouts/index.html is the name we register the template with – and the template itself is merged with the base template. I’m not sure how we could improve on that.

Not sure it needs improvement. My mistake in this case was being much to much focused on the block definitions as error source instead examinating all codeblocks (such as the partials calls e.g.). A matter of selective perception …