문제

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" />
도움이 되었습니까?

해결책

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.

다른 팁

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']
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top