使用模板的Grails嵌套标记库?
我想创建标记库来简化表示用户仪表板的网页。我想创建两个标记库。第一个是将在其他地方使用的通用面板,第二个是面板的更具体版本 GSP由以下型号的控制器调用:使用模板的Grails嵌套标记库?,grails,taglib,Grails,Taglib,我想创建标记库来简化表示用户仪表板的网页。我想创建两个标记库。第一个是将在其他地方使用的通用面板,第二个是面板的更具体版本 GSP由以下型号的控制器调用: def index() { def timelineItems = [ [details: "Some text"], [details: "Some other text"] ] render(view: "index", model: [timelineItems: timelin
def index() {
def timelineItems = [
[details: "Some text"],
[details: "Some other text"]
]
render(view: "index", model: [timelineItems: timelineItems])
}
我想要的普惠制如下所示:
<dash:panel panelClass="col-lg-8" panelTitle="Service History">
<p>Some text in the body here</p>
<dash:timelinePanel timelineItems="$timelineItems" />
</dash:panel>
我的地图似乎正在转换为字符串,我无法访问该地图。请问我做错了什么?我想定义多个标记,它们可以在彼此内部使用。如何执行此操作?您必须在
破折号:timelinePanel
中使用{}
作为
。如果没有此插值,$timelineItems
将被视为字符串。顺便说一句,您可以直接从gsp使用g:render template=
,而不引入TagLibThank@dmahapatro和Igor,这样就消除了导致应用程序崩溃的错误。但是,我现在将输出视为单个字符串:“正文中的一些文本我们希望在主面板中显示的一些文本我们希望在第二个主面板中显示的一些文本”“我可以做些什么来将时间线模板的内容解释为字符串吗?啊,似乎我需要将编码设置为“raw”,以使其正常工作。因此,在timelinePanel标记库中,将“encoding:“raw”作为映射中的一个项(或者使raw成为整个标记库类的默认编码)。
def panel = {attrs, body ->
out << render(template: "/dashboard/dashboardPanel", model:[panelClass: attrs.getAt("panelClass"), panelTitle: attrs.getAt("panelTitle"), body: body()])
}
def timelinePanel = { attrs ->
out << render(template: "/dashboard/dashboardTimelinePanel", model: [timelineItems: attrs.getAt("timelineItems")])
}
<div class="${panelClass}">
<div class="panel panel-default">
<div class="panel-heading">
${panelTitle}
</div>
<div class="panel-body">
${body}
</div>
</div>
</div>
<g:each in="${timelineItems}">
<p>${it.details}</p>
</g:each>
Some text in the body here
<p>Some text</p>
<p>Some other text</p>
Error evaluating expression [it.details] : No such property: details for class: java.lang.String