Expand my Community achievements bar.

SOLVED

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

Avatar

Level 3

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

3 Replies

Avatar

Community Advisor

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

 

 

Avatar

Community Advisor

@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.

Avatar

Correct answer by
Community Advisor

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