Search.json unexpected EOF when starting development server

Implementing web site search capabilities includes using this searh.json file:

{
  "results": [
    {{- range $index, $page := .Site.RegularPages }}
    {{- if $index -}} , {{- end }}
      {
        "href": {{ .Permalink | jsonify }},
        "title": {{ .Title | jsonify }},
        "body": {{ .Content | plainify | jsonify }}
      }
  
  ]
}

When I try to sart the hugo development server I get this error:

$ hugo server
Error: add site dependencies: load resources: loading templates:
".../themes/tikva/layouts/_default/search.json:13:1":
parse failed: template: _default/search.json:13: unexpected EOF

The file seems complete to me and I don’t understand why there’s an
unexpected EOF when the enclusing braces match. Please educate me why this error exists.

You need an end statement on that range… You should get a message but maybe because it’s json the error is not so explicit.

2 Likes

Thanks. I’ll look in my javascript book and learn how to add the ‘end’
statement.

Rich

No.

https://gohugo.io/templates/introduction/#iteration

1 Like

Thank you, Joe.

Much appreciated,

Rich

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