10

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" />
Saraph
  • 992
  • 1
  • 11
  • 25

3 Answers3

25

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.

James Kleeh
  • 12,094
  • 5
  • 34
  • 61
10

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

penguin
  • 724
  • 5
  • 11
2

Try with:

static defaultEncodeAs = [taglib:'text']
Eduardo Cuomo
  • 17,828
  • 6
  • 117
  • 94
  • 2
    Please if you want to get more upvotes you have to explain your answer. Your answer might solve the problem but not give information about what was wrong and whay was wrong. – Raydel Miranda Aug 03 '15 at 21:22