Hi Team,
I am trying to read custom property from jcr:content through sling model it is working as expected.
properties.get("xyz:description", String.class))
but xyz:description having html content which is having all html tags.
Ex:-xyz:description
<div class="ExternalClassA70F215EC26842B6AB7B672B13D0276A"><p>With improved upfront , circle<sup>TM</sup> ABC-01 enhances flavors and offers strong synergy with stevia and <b>HFCS</b> <u></u>.<br></p></div>
but when I read through properties.get("xyz:description", String.class)), I am getting plain text , superscirpt, bold are not applied in the text.
.
Could you please suggest how to read html content from jcr:content properties.
Thanks,
Chandra
Solved! Go to Solution.
Views
Replies
Total Likes
I am getting complete html. In sling model use property as:
@ValueMapValue private String text; @Override public String getText() { return text; }
At Ui side, Use below to render:
<sly data-sly-use.model="<your-slingmodel">
${model.text @context='html'}
Hope this helps!
Hi @chandrareddy, I just checked on my local and I was able to get the HTML markup using properties.get("propertName", String.class) using HTL as ${item.propertyName}.
When I added the context as HTML - ${item.propertyName @ context = "html"}, I was able to output the HTML on to the page.
Please check the HTL context you're passing - https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#121-display-context
- Jineet
Thank you Jineet.
Hi @chandrareddy , Please use Sling API instead of JCR API to read properties in Models. I give you this piece of code for your reference and hope this helps!
// Injecting property value using ValueMap @ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) @Nullable private String text; @Override public String getText() { return text; }
Here is how you write in HTL.
<div class="text">${properties.text @context='html'}</div>
Regards,
Aditya.ch
Thank you Aditya
As @Jineet_Vora to see the html take effect you need to use the context html -> @ context = "html"
I am getting complete html. In sling model use property as:
@ValueMapValue private String text; @Override public String getText() { return text; }
At Ui side, Use below to render:
<sly data-sly-use.model="<your-slingmodel">
${model.text @context='html'}
Hope this helps!
Views
Likes
Replies
Views
Likes
Replies