Sar*_*aph 10 grails groovy templates taglib
我正在尝试从taglib渲染我的模板:
out << g.render(template: "/menu/sidebar")
Run Code Online (Sandbox Code Playgroud)
这就是我的侧边栏模板的样子:
<ul>
<li>TEST1</li>
<li>TEST2</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
当我在浏览器中检查我的页面时,整个模板代码出现在这样的撇号中......
"<ul>
<li>TEST1</li>
<li>TEST2</li>
</ul>"
Run Code Online (Sandbox Code Playgroud)
...并打印我的HTML代码就像纯文本一样.知道如何让它将内容识别为正确的HTML代码吗?
编辑: Taglib代码:
class MenuTagLib {
static defaultEncodeAs = 'html'
def renderIfExists = { attrs,body->
GrailsConventionGroovyPageLocator groovyPageLocator
println attrs.template
if(groovyPageLocator.findTemplateByPath(attrs.template))
{
g.render(template:attrs.template)
}
else{
out << g.render(template: "/menu/sidebar")
}
}
}
Run Code Online (Sandbox Code Playgroud)
调用它的方式:
<g:renderIfExists template="/${params.controller}/sidebar" plugin="untitled1" />
Run Code Online (Sandbox Code Playgroud)
pen*_*uin 10
标记库默认将标记内容编码为Grails 2.3中的HTML.可以通过添加禁用此功能
static defaultEncodeAs = "raw"
Run Code Online (Sandbox Code Playgroud)
这将使您的标记lib输出为原始html而不是字符串