escaping HTML code

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

escaping HTML code

sagargaikwad
I want to include following code in thyme page at run time

<img src="xyz.com?temp1=value1&temp2=value2&temp3=value3">

I have following code in thyme page to include above snippet


<div th:if="${someCondition == true}" th:utext="${aboveImageSnippet}">Demo URL</div>


So it is giving me following error

org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 119; The reference to entity "temp2" must end with the ';' delimiter.


if I replace '&' with '&' then it is working. but i don't want to this.
Reply | Threaded
Open this post in threaded view
|

Re: escaping HTML code

danielfernandez
Administrator
Hi,

Thymeleaf needs your markup to be well formed, and this means no & or < should be unescaped inside a tag's attribute (both XML and XHTML specifications forbid this), so you should be using "&amp;" for your &'s inside that URL.

Don't worry, your URL will work perfectly doing so. In fact, it is the correct way of doing it.

Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|

Re: escaping HTML code

prem
Thanks daniel ... this worked for me

Ticketgoose.com