เทมเพลตที่ซ้อนกันใน Revel โหลดไม่ถูกต้อง

เมื่อฉันเรียกเทมเพลตที่ซ้อนกัน {{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

คำถามของฉันคือ: ข้อความแสดงข้อผิดพลาดนั้นหมายความว่าอย่างไร มันจะโหลด 4 บรรทัดบนสุดของไฟล์ mirror.html เสมอ ไม่ว่า 4 บรรทัดบนสุดจะเป็นอะไรก็ตาม


person mxplusb    schedule 07.09.2016    source แหล่งที่มา


คำตอบ (1)


ข้อผิดพลาดไม่ได้อยู่ใน mirror.html แต่อยู่ใน index.html:

results.go:232: ข้อผิดพลาดในการดำเนินการเทมเพลต (ใน Mirror/index.html): html/template:Mirror/index.html: "\"" ในชื่อแอตทริบิวต์: " 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"
person icza    schedule 07.09.2016