0
Play2模板引擎存在問題。一些變量在渲染過程中不被解釋。play2模板上的變量未解釋
變量{key.getKey}在被雙引號引起時不被解釋。我能如何解決這個問題?
PLAY 2.2.3 TEMPLATE(index.scala.html)
@flash
@(if (flash.size > 0) {
flash.entrySet.iterator.map { key =>
<div class="row">
<div class="large-12 columns">
<div class="alert-box radius {key.getKey}" data-alert="">
{key.getKey.toUpperCase} — {key.getValue}
<a href="#" class="close">×</a>
</div>
</div>
</div>
}
})
HTML OUTPUT:
{"success": "The item has been created"}
<div class="row">
<div class="large-12 columns">
<div class="alert-box radius {key.getKey}" data-alert="">
SUCCESS — The item has been created
<a href="#" class="close">×</a>
</div>
</div>
</div>
PLAY 2.2.3 TEMPLATE(index.scala.html)與@可變
@flash
@(if (flash.size > 0) {
flash.entrySet.iterator.map { key =>
<div class="row">
<div class="large-12 columns">
<div class="alert-box radius @{key.getKey}" data-alert="">
{key.getKey.toUpperCase} — {key.getValue}
<a href="#" class="close">×</a>
</div>
</div>
</div>
}
})
HTML輸出:
{"success": "The item has been created"}
<div class="row">
<div class="large-12 columns">
<div class="alert-box radius @{key.getKey}" data-alert="">
SUCCESS — The item has been created
<a href="#" class="close">×</a>
</div>
</div>
</div>
我已經嘗試解決方案,unfortunaly,變量仍不能解釋(見我的編輯職位)。 「{key =>」塊中的代碼被解釋爲一個XML文檔(當html標籤錯誤時,我得到XML錯誤) – 0xBAADF00D
「flash」的類型是什麼?還有更多這個源文件嗎?我自己試了一下(在視圖中只使用你的代碼),它工作,所以需要更多的信息。 –
這是Play 2.2.3提供的默認flash var。在我的控制器中,我只是把這個代碼 - >閃光(「成功」,「項目已創建」); – 0xBAADF00D