Adam Carlin
Adam Carlin

Reputation: 244

Convert string to html

I've currently got a string that is stored as html. When I output this to the gsp page I just get plain text.

<g:each in="${fixtureInView.links}">
    <h1>Link :${it.encodeAsHTML()}</h1>
</g:each>

Currently displays Link :&lt;a href=&#39;http://www.google.co.uk&#39;&gt;Google&lt;/a&gt;

and if I change it to decodeHTML it shows <a href='http://www.google.co.uk'>Google</a>

When I try just ${it} I get Link :&lt;a href=&#39;http://www.google.co.uk&#39;&gt;Google&lt;/a&gt;

Any ideas?

Upvotes: 2

Views: 4758

Answers (2)

Adam Carlin
Adam Carlin

Reputation: 244

I've figured this out. If you place raw() round the variable that is html code, it will let the raw html be rendered as html and not as a string.

Upvotes: 9

user1791574
user1791574

Reputation: 1749

In list save your link like this.

"<a href=\"google.com\">Google</a>"

And print it like this.

<g:each in="${fixtureInView.links}">
            <h1>Link :${it}</h1>
 </g:each>

It will work for you.

Upvotes: 0

Related Questions