Issues in using pageproperties in Underscore JS | Community
Skip to main content
Level 5
Jul 30, 2020 6:09 AM UTC
Solved

Issues in using pageproperties in Underscore JS

Hello All - I am using Underscore JS for component creation. The below snippet is not working for the page properties. Can someone tell how to address this?

 

<script type="text/template" id="testView">
<% _.each(test, function(test) { %>
<div class="templatetest">
<sly data-sly-test=" <% ${properties.displayimages} %> ">     (This line of code doesn't work)
<img src="<%= test.image %>" class="w-full" alt="">
</sly>
</div>
<% });%>
</script>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Suraj_Kamdi
Suraj_KamdiAccepted solution
New Participant
Jul 30, 2020 7:32 AM UTC

@v1101 

Use context="unsafe"

 

<sly data-sly-test=" <% ${properties.displayimages @context="unsafe"} %> "> 

 

I hope this will help.

3 replies

Suraj_Kamdi
New Participant
Jul 30, 2020 8:54 AM UTC

@v1101 

updating above

<div class="templatetest">

   <sly data-sly-test="${properties.displayimages @context='unsafe'}"> 

       <img src="<%= test.image %>" class="w-full" alt="">

   </sly> 

</div>

Translate
Suraj_Kamdi
Suraj_KamdiAccepted solution
New Participant
Jul 30, 2020 7:32 AM UTC

@v1101 

Use context="unsafe"

 

<sly data-sly-test=" <% ${properties.displayimages @context="unsafe"} %> "> 

 

I hope this will help.

Translate
ArpitVarshney
New Participant
Jul 30, 2020 6:59 AM UTC

Hi @v1101 

It seems you are mixing JSP and HTL syntaxes. If your script file contains extension as .html then follow HTL documentation else follow JSP.

 

It looks like your script file is JSP as most of your shared code follows JSP syntaxes and JSP doesn't support sly and data-sly-test. It is HTL syntax of testing an expression. Please go through the link to get the corresponding syntax https://stackoverflow.com/questions/28409916/how-to-check-null-from-jcr-value-in-adobe-cq5

 

Regards.

Arpit Varshney

Translate