Ana Franco
Ana Franco

Reputation: 1801

Show multiline text in grails page

I'm going mad with this, I need to show a text I got from a textarea in grails 2.3.7 but when I replace \r\n characters for br/ and do an encodeAsHTML() I get the br's every where instead of new lines.

How is it done? this is what I've tried:

${cotizacionInstance.descripcion.encodeAsHTML().replaceAll('\r\n', '<br/>')}

${cotizacionInstance.descripcion.replaceAll('\r\n', '<br/>').encodeAsHTML()}

<%=cotizacionInstance.descripcion.replaceAll('\r\n', '<br/>').encodeAsHTML()%>

<%=cotizacionInstance.descripcion.encodeAsHTML().replaceAll('\r\n', '<br/>')%>

<%=cotizacionInstance.descripcion.replaceAll('\r\n', '<br/>').decodeHTML()%>

<%=cotizacionInstance.descripcion.decodeHTML().replaceAll('\r\n', '<br/>')%>

I don't like the way it comes out if I use the pre tag, because I loose all responsiveness.

I see that in the google chrome inspector I get my string between double quotes but I don't know how to remove those.

Thanks

Upvotes: 2

Views: 1744

Answers (2)

Chris
Chris

Reputation: 8109

You need to esacpe your backslashes:

replaceAll("\\n", "<br/>")

Upvotes: 0

Jeff Scott Brown
Jeff Scott Brown

Reputation: 27200

There are factors left out of your description which make it impossible to say for sure but one way to get the behavior you are after is to mark the text as raw with something like this...

${raw(cotizacionInstance.descripcion.replaceAll('\r\n', '<br/>'))}

I hope that helps.

Upvotes: 5

Related Questions