Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails: Rendering template from taglib as HTML

I'm trying to render my template from taglib:

out << g.render(template: "/menu/sidebar")

This is what my sidebar template looks like:

<ul>
    <li>TEST1</li>
    <li>TEST2</li>
</ul>

When I inspect my page in browser, whole template code appears in apostrophes like this...

"<ul>
    <li>TEST1</li>
    <li>TEST2</li>
</ul>"

...and prints my html code just like a plain text. Any idea how to make it recognize the content as proper html code?

Edit: Taglib code:

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")
        }
    }
}

The way of calling it:

<g:renderIfExists template="/${params.controller}/sidebar" plugin="untitled1" />
like image 321
Saraph Avatar asked Aug 14 '13 11:08

Saraph


2 Answers

Try with:

static defaultEncodeAs = [taglib:'text']
like image 137
Eduardo Cuomo Avatar answered Sep 29 '22 10:09

Eduardo Cuomo


If I had to guess, it would be that you have this in your class:

static defaultEncodeAs = 'html'

You should remove that line and try it again. That says that it should escape html characters.

like image 29
James Kleeh Avatar answered Sep 29 '22 10:09

James Kleeh