Question

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" />
Was it helpful?

Solution

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.

OTHER TIPS

Tag libraries default to encoding tag contents as HTML as of Grails 2.3. This can be disabled by adding

 static defaultEncodeAs = "raw"

This will let your tag lib output be raw html instead of as a string

Try with:

static defaultEncodeAs = [taglib:'text']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top