<sly data-sly-use.product="**.**.**.**.**.models.product">
<script type="application/ld+json"> {
"@context": "http://schema.org",
"@type": "Product",
"name": "${product.name }",
<sly data-sly-test="${product.getReviewSummary != 0 && product.getReviewCount != 0}">
"aggregateRating": {
"ratingValue": "${product.getReviewSummary }",
"reviewCount": "${product.getReviewCount }"
}</sly>
}
</script>
</sly>
output:
<script type="application/ld+json"> {
"@context": "http://schema.org",
"@type": "Product",
"name": "jean",
<sly data-sly-test="">
"aggregateRating": {
"ratingValue": "4.0",
"reviewCount": "2"
}
</sly>
}
</script>
issue is in output <sly data-sly-test=""> tag is getting in json how to avoid it.
Solved! Go to Solution.
Views
Replies
Total Likes
HI @user96222
You can construct the ld+json in the Sling Model with business logic and return as String and use
jsonLDStr = GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create().toJson(jsonLDObj);
<script type="application/ld+json">
${myObj.jsonLD @ context='scriptComment'}
</script>
Hi @user96222,
We cannot get rid of the sly tag from the script. We had similar issue so we ended up forming the json object in Sling model -
and then used the schema object in HTL -
Or you can try using javascript to form the json.
@chavad @user96222 Be careful setting "unsafe" context as this disables XSS protection completely.
Hi @user96222
I believe you already received answers to this in your previous thread: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/htl-issue/m-p/719017#M1772...
This is different
You are right. This is a different issue. I misreas. Apologies.
Unless you want to wrap the entire script in a data-sly-test twice for both true and false cases, I advice you prepare your json on sling model and provides it in one go to the component ( same as @arunpatidar indicated ).
Hi @user96222 ,
Can you try updating data-sly-test condition on line 2 and try to execute. Check if the issue still persists
Hope this helps
Thanks
HI @user96222
You can construct the ld+json in the Sling Model with business logic and return as String and use
jsonLDStr = GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create().toJson(jsonLDObj);
<script type="application/ld+json">
${myObj.jsonLD @ context='scriptComment'}
</script>
I second this, moving the business logic to back-end(sling models).
HTL is mainly presentation.