Templat bersarang di Revel tidak dimuat dengan benar

Saat saya memanggil templat bersarang, {{template "partials/mirror.html" .}}, kesalahan ini muncul:

results.go:232: Template Execution Error (in App/index.html): html/template:App/index.html: "\"" in attribute name: " class\"quote-component\" id=\"quot"

Jika saya membuat pengontrol khusus untuk template yang dipanggil App/index.html, seperti ini:

package controllers

import "github.com/revel/revel"

type Mirror struct {
    *revel.Controller
}

func (m Mirror) Index() revel.Result {
    return m.Render()
}

Saya masih mendapatkan:

results.go:232: Template Execution Error (in Mirror/index.html): html/template:Mirror/index.html: "\"" in attribute name: " class\"quote-component\" id=\"quot"

Berikut isi 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>

Struktur aplikasi mengikuti rekomendasi Revel, proyek itu sendiri baru saja memigrasikan proyek ini dari Node untuk Pergi menggunakan Revel.

Pertanyaan saya adalah: apa maksud pesan kesalahan itu? Itu selalu memuat 4 baris teratas dari file mirror.html, terlepas dari 4 baris teratasnya.


person mxplusb    schedule 07.09.2016    source sumber


Jawaban (1)


Kesalahannya bukan di mirror.html tetapi di index.html:

results.go:232: Kesalahan Eksekusi Templat (dalam Mirror/index.html): html/template:Mirror/index.html: "\"" dalam nama atribut: " class\"quote-component \"id=\"quot"

Anda cukup menghilangkan tanda sama dengan '=' saat menentukan atribut class dari beberapa elemen, misalnya Anda menulis:

<span class"quote-component" id="quot">...

Lihat contoh sederhana ini untuk memverifikasi:

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)

Output: hampir sama dengan milik Anda (cobalah di Go Playground):

html/template: "\"" in attribute name: " class\"quote-component\" id=\"quot"
person icza    schedule 07.09.2016