próbuję uczynić mój szablon z TagLib:Grails: Renderowanie szablonu z TagLib jako HTML
out << g.render(template: "/menu/sidebar")
To właśnie mój szablon sidebar wygląda następująco:
<ul>
<li>TEST1</li>
<li>TEST2</li>
</ul>
Kiedy sprawdzać moją stronę w przeglądarce, cały kod szablonu pojawia się w apostrofy tak ...
"<ul>
<li>TEST1</li>
<li>TEST2</li>
</ul>"
... i drukuje mój kod HTML, podobnie jak PLA w tekście. Masz pomysł, jak sprawić, by treść była rozpoznawalna jako właściwy kod HTML?
Edit: TagLib Kod:
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")
}
}
}
Sposób nazywając go:
<g:renderIfExists template="/${params.controller}/sidebar" plugin="untitled1" />
AFAIK, 'out << render (template: "/ menu/sidebar") 'powinno to zrobić ... –
Czyni to samo – Saraph
Czy możesz umieścić swój kod taglib i sposób w jaki go wywołujesz? –