Reputation: 105
I am trying to build a simple Hugo project. The problem is that I am trying to create some basic layouts and I get an error when rendering.
Inside the /layouts/_default I have the following:
baseof.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ .Site.Title }} | {{ .Title }}>
</head>
<body>
<header>
<p>this is a header</p>
</header>
<main>
{{ block "main" . }}
{{ end }}
</main>
<footer>
<p>this is a footer</p>
</footer>
</body>
</html>
list.html
{{ define "main" }}
<h2>List</h2>
{{.Content}}
<!-- prettier-ignore -->
{{ range .Pages }}
<div>
<a href="{{.Permalink}}">{{.Title}}</a>
<p>{{ dateFormat "Monday, Jan 2, 2006" .Date }}</p>
</div>
{{ end }}
<!-- prettier-ignore -->
{{ end }}
single.html
{{ define "main" }}
<h1>{{ .Title }}</h1>
<h2>{{ .PublishDate }}</h2>
{{ .Content }}
<!-- prettier-ignore -->
{{ end }}
When I try running, I get the following error (same error both for single.html
and for list.html
):
2020/09/12 20:33:30 Failed to render pages: render of "page" failed: execute of template failed: html/template:_default/single.html: ends in a non-text context: {stateRCDATA delimNone urlPartNone jsCtxRegexp attrNone elementTitle }
Can you give me any suggestions?
Upvotes: 1
Views: 1497
Reputation: 1324737
This is an error directly from Go itself: package html/template
... ends in a non-text context: ...
"Example:
<div
<div title="no close quote>
<script>f()
Executed templates should produce a
DocumentFragment
of HTML.Templates that end without closing tags will trigger this error.
Templates that should not be used in an HTML context or that produce incomplete Fragments should not be executed directly.{{define "main"}} <script>{{template "helper"}}</script> {{end}} {{define "helper"}} document.write(' <div title=" ') {{end}}
"
helper
" does not produce a valid document fragment, so should not be Executed directly.
Simplify your single.html
page in order to check if your baseof.html
base template has the issue.
Not only <title>
is suspect, as noted, but the <meta>
tags are not closed either:
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Upvotes: 1
Reputation: 177
<title>{{ .Site.Title }} | {{ .Title }}>
should be
<title>{{ .Site.Title }} | {{ .Title }}</title>
Upvotes: 1