Read custom property from jcr:content through sling model | Community
Skip to main content
Level 2
Oct 12, 2022 4:22 PM UTC
Solved

Read custom property from jcr:content through sling model

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

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
HeenaMadan
HeenaMadanAccepted solution
New Participant
Oct 13, 2022 9:24 AM UTC

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!

6 replies

HeenaMadan
HeenaMadanAccepted solution
New Participant
Oct 13, 2022 9:24 AM UTC

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!

Translate
Level 2
Oct 13, 2022 8:05 AM UTC

As @jineet_vora to see the html take effect you need to use the context html -> @ context = "html"

Translate
Aditya_Chabuku
New Participant
Oct 12, 2022 6:30 PM UTC

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

 

Translate
Thanks,Aditya Chabuku
Level 2
Oct 20, 2022 1:32 PM UTC

Thank you Aditya

Translate
Jineet_Vora
New Participant
Oct 12, 2022 5:51 PM UTC

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

Translate
Level 2
Oct 20, 2022 1:32 PM UTC

Thank you Jineet.

Translate