Sling Model not showing complete details -- Sling model to JS | Community
Skip to main content
Prashardan
Level 4
August 31, 2023
Solved

Sling Model not showing complete details -- Sling model to JS

  • August 31, 2023
  • 3 replies
  • 985 views

Hi Team

 

I have a sling model which I am using in htl file but I few values are not getting printed. 

 

<sly data-sly-use.helper="${'com.****.aem.****.helpers.SampleModel'}"/>

<p> address is ${helper.deliveryAddress.firstName} </p>

 

My deliverAddress() method is having some address details like firstName, line1, line2, street

I am able to print firstName and line1 but not line2 and street. 

 

There is another sling model which is able to retrieve all  firstName, line1, line2, street which I used that sling model in my htl file it is printing however printing in some other htl file.

 

Kindly help me if I am doing any mistake.

 

Also let me know how to take value from sling model to js so that I can see what deliveryAddress() is printing.

 

Thanks and Regards

Prashanthi

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by EstebanBustamante

Most likely you are missing the proper context, If the value contains some special character HTL will avoid printing the values for security reasons, that's why you should always use the proper context. 


Try something like this:

<p> address is ${helper.deliveryAddress.firstName @ context='html'} </p>

Please read more about context here: https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#121-display-context 

3 replies

ksh_ingole7
Community Advisor
Community Advisor
August 31, 2023

Hi @prashardan 

 

Try adding a debugger in your code. Check what values are flowing into the code before you fetch them into your HTL. 

Start your AEM local instance in Debug mode. 

Follow this document to check how to debug AEM : https://aemgeeks.com/aem-debugging/how-to-start-aem-in-debug-mode/

 

Check if the line2 values is coming into your Sling Model. 

 

Also if your use the debugger you would not have to get the value in JS to see it. 

You can also try printing helper.deliveryAddress to see what exactly is coming from Sling model. 

 

Thanks

 

 

Sudheer_Sundalam
Community Advisor
Community Advisor
August 31, 2023

@prashardan ,

We need to look at your sling model and the HTL file to guide you better with your issue. Please post your sling model and htl file if you can.

EstebanBustamante
Community Advisor and Adobe Champion
EstebanBustamanteCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
August 31, 2023

Most likely you are missing the proper context, If the value contains some special character HTL will avoid printing the values for security reasons, that's why you should always use the proper context. 


Try something like this:

<p> address is ${helper.deliveryAddress.firstName @ context='html'} </p>

Please read more about context here: https://github.com/adobe/htl-spec/blob/1.4/SPECIFICATION.md#121-display-context 

Esteban Bustamante