Revel 中的嵌套模板无法正确加载
Nested template in Revel not loading properly
当我调用嵌套模板 {{template "partials/mirror.html" .}}
时,它抛出此错误:
results.go:232: Template Execution Error (in App/index.html): html/template:App/index.html: "\"" in attribute name: " class\"quote-component\" id=\"quot"
如果我专门为 App/index.html
正在调用的模板创建控制器,如下所示:
package controllers
import "github.com/revel/revel"
type Mirror struct {
*revel.Controller
}
func (m Mirror) Index() revel.Result {
return m.Render()
}
我仍然得到:
results.go:232: Template Execution Error (in Mirror/index.html): html/template:Mirror/index.html: "\"" in attribute name: " class\"quote-component\" id=\"quot"
以下是mirror.html
的内容:
<!-- AUTH STATES -->
<section class="auth-states">
<!-- FACE DETECTED W/IN RANGE -->
{{template "partials/faceClose.html" .}}
<!-- USER DETECTED -->
{{template "partials/userDetected.html" .}}
<!-- NON USER DETECTED -->
{{template "partials/nonUserDetected.html" .}}
<!-- TIME OUT LOGS USER OUT -->
{{template "partials/loggingOut.html" .}}
</section>
<div class="clear eyelevel">
<!-- WEATHER-->
{{template "partials/weather.html" .}}
<!-- TIMELY CONTENT: TIMESTAMP AND ALERTS -->
<div class="timely-content">
<!-- TIMESTAMP -->
{{template "partials/timestamp.html" .}}
<!-- EMOTION -->
{{template "partials/emotion.html" .}}
</div>
</div>
<img id="shot-preview"/>
<!-- LOW PRIORITY CONTENT -->
<section class="low-pri-content auth-content">
<h2 class="logged-in-stamp">
Here's the scoop, <span id="logged-in-name"></span>:
</h2>
{{template "partials/traffic.html" .}}
{{template "partials/stocks.html" .}}
{{template "partials/newsFeed.html" .}}
</section>
<div id="video-hidden" aria-hidden="true">
<video id="cameraPreview" class="cameraPreview"></video>
</div>
<script src="https://code.jquery.com/jquery-2.2.1.js"></script>
<script src="https://cdn.jsdelivr.net/momentjs/2.11.2/moment.min.js"></script>
<script src="/public/js/weather.js"></script>
<script src="/public/js/stock.js"></script>
<script src="/public/js/news.js"></script>
<script src="/public/js/traffic.js"></script>
<script src="/public/js/mirror.js"></script>
<script src="/public/js/authenticate.js"></script>
应用程序的结构遵循 Revel 的建议,项目本身只是使用 Revel this project 从 Node 迁移到 Go。
我的问题是:该错误消息是什么意思?它总是加载 mirror.html
文件的前 4 行,不管前 4 行是什么。
错误不在mirror.html
中,而是在index.html
中:
results.go:232: Template Execution Error (in Mirror/index.html): html/template:Mirror/index.html: "\"" in attribute name: " class\"quote-component\" id=\"quot"
您在指定某个元素的 class
属性时只是漏掉了一个等号 '='
,例如您写道:
<span class"quote-component" id="quot">...
看这个简单的例子来验证:
const templ = `<html><body>
<span class"quote-component" id="quot">Bad syntax</span>
</body></html>`
t := template.Must(template.New("").Parse(templ))
err := t.Execute(os.Stdout, nil)
fmt.Println(err)
输出:与您的几乎相同(在 Go Playground 上尝试):
html/template: "\"" in attribute name: " class\"quote-component\" id=\"quot"
当我调用嵌套模板 {{template "partials/mirror.html" .}}
时,它抛出此错误:
results.go:232: Template Execution Error (in App/index.html): html/template:App/index.html: "\"" in attribute name: " class\"quote-component\" id=\"quot"
如果我专门为 App/index.html
正在调用的模板创建控制器,如下所示:
package controllers
import "github.com/revel/revel"
type Mirror struct {
*revel.Controller
}
func (m Mirror) Index() revel.Result {
return m.Render()
}
我仍然得到:
results.go:232: Template Execution Error (in Mirror/index.html): html/template:Mirror/index.html: "\"" in attribute name: " class\"quote-component\" id=\"quot"
以下是mirror.html
的内容:
<!-- AUTH STATES -->
<section class="auth-states">
<!-- FACE DETECTED W/IN RANGE -->
{{template "partials/faceClose.html" .}}
<!-- USER DETECTED -->
{{template "partials/userDetected.html" .}}
<!-- NON USER DETECTED -->
{{template "partials/nonUserDetected.html" .}}
<!-- TIME OUT LOGS USER OUT -->
{{template "partials/loggingOut.html" .}}
</section>
<div class="clear eyelevel">
<!-- WEATHER-->
{{template "partials/weather.html" .}}
<!-- TIMELY CONTENT: TIMESTAMP AND ALERTS -->
<div class="timely-content">
<!-- TIMESTAMP -->
{{template "partials/timestamp.html" .}}
<!-- EMOTION -->
{{template "partials/emotion.html" .}}
</div>
</div>
<img id="shot-preview"/>
<!-- LOW PRIORITY CONTENT -->
<section class="low-pri-content auth-content">
<h2 class="logged-in-stamp">
Here's the scoop, <span id="logged-in-name"></span>:
</h2>
{{template "partials/traffic.html" .}}
{{template "partials/stocks.html" .}}
{{template "partials/newsFeed.html" .}}
</section>
<div id="video-hidden" aria-hidden="true">
<video id="cameraPreview" class="cameraPreview"></video>
</div>
<script src="https://code.jquery.com/jquery-2.2.1.js"></script>
<script src="https://cdn.jsdelivr.net/momentjs/2.11.2/moment.min.js"></script>
<script src="/public/js/weather.js"></script>
<script src="/public/js/stock.js"></script>
<script src="/public/js/news.js"></script>
<script src="/public/js/traffic.js"></script>
<script src="/public/js/mirror.js"></script>
<script src="/public/js/authenticate.js"></script>
应用程序的结构遵循 Revel 的建议,项目本身只是使用 Revel this project 从 Node 迁移到 Go。
我的问题是:该错误消息是什么意思?它总是加载 mirror.html
文件的前 4 行,不管前 4 行是什么。
错误不在mirror.html
中,而是在index.html
中:
results.go:232: Template Execution Error (in Mirror/index.html): html/template:Mirror/index.html: "\"" in attribute name: " class\"quote-component\" id=\"quot"
您在指定某个元素的 class
属性时只是漏掉了一个等号 '='
,例如您写道:
<span class"quote-component" id="quot">...
看这个简单的例子来验证:
const templ = `<html><body>
<span class"quote-component" id="quot">Bad syntax</span>
</body></html>`
t := template.Must(template.New("").Parse(templ))
err := t.Execute(os.Stdout, nil)
fmt.Println(err)
输出:与您的几乎相同(在 Go Playground 上尝试):
html/template: "\"" in attribute name: " class\"quote-component\" id=\"quot"