Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Conversion of & to &

Avatar

Level 2

Hi,

We are using HTL for component development.

The title field is populated dynamically and contains the character '&': example : Audio & Video.

When we "View page source"  & is converted to & due to html encoding. example : Audio & Video

We want to avoid this encoding and & should be displayed as & itself.

context="unsafe" and context="scriptToken" avoids encoding and helps to resolve the issue, but these are not recommended and accepted by the client.

We have tried using StringUtils,encode(), StringUtils.escape() methods but it did not work as expected

Are there any other alternatives through which this can be achieved. Any pointers would help

1 Accepted Solution

Avatar

Correct answer by
Level 6

use <div>${properties.text @ context='html'}</div>

context='html' will convert &amp; to & on page

View solution in original post

4 Replies

Avatar

Employee

Normally character like & < > are always encoded, why is this not the case at your components?

Avatar

Level 2

Hi Feike,

On the page the value is displayed correctly.

Its only when we try viewing page source code it is converted to '&amp;'

We want '&' to display as '&' only when we view page source as well.

Avatar

Correct answer by
Level 6

use <div>${properties.text @ context='html'}</div>

context='html' will convert &amp; to & on page