Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render Domain Field as HTML in GSP?

Tags:

grails

gsp

I have a domain. User with a field description. In my Grails GSP page I can display it as:

${user.description}

The problem is that description contains valid html content like this:

<ul><li>test</li><li>test2</li><li>test3</li></ul><br>

This content should be rendered to be visible as HTML instead of a String.

How can I render a String containing HTML as HTML on a GSP?

like image 710
Sven Bauer Avatar asked Dec 25 '22 17:12

Sven Bauer


1 Answers

To generate raw output use any of the following:

${raw(user.description)}

or

${user.description.encodeAsRaw()}

You can read this blog post that details this further. In later versions the default codec being used is HTML. You can control the default codec via Config.groovy.

like image 62
Joshua Moore Avatar answered Jan 03 '23 03:01

Joshua Moore