HTL issue | Community
Skip to main content
Level 3
November 11, 2024
Solved

HTL issue

  • November 11, 2024
  • 2 replies
  • 822 views

 

I am trying to add a JSON-LD script through a component in HTML. I created an HTML file named productjson.html where I added the below script:

<sly data-sly-use.product="com.**.**.**.******.Product">

<script type="application/ld+json">{
"@context": "http://schema.org",
"@type": "Product",
"offers": "${product.offersjson}",
}
</script>

</sly>

 

Then, in the component's main HTML file, I included the productjson.html using the following tag:

<sly data-sly-include="productjson.html" />

 

 

output: in  view page source in getting 

<

ACTUAL:

"offers": [
{
&#34;image&#34;: &#34;https:/in_1.jpg&#34;,
,
&#34;priceCurrency&#34;: &#34;USD&#34;,


&#34;price&#34;: 38,
},]

 

EXPECTED

"offers": [
{
"image": "https:/in_1.jpg",
"priceCurrency" :"usd"
"price" : "38"
},]

some  decoding issue, if i try print that json in page it is getting properly from backend but  in view page source &#34; getting add

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 Tethich

Hi @user96222 

 

Try

"offers": "${product.offersjson @ context='unsafe'}"

2 replies

Saravanan_Dharmaraj
Community Advisor
Community Advisor
November 11, 2024

@user96222 Could you verify if the space is missing in script tag with type parameter? 

<scripttype= 

user96222Author
Level 3
November 11, 2024

Thanks @saravanan_dharmaraj , now added it properly but 
output is as below

ACTUAL:

"offers": [
{
&#34;image&#34;: &#34;https:/in_1.jpg&#34;,
,
&#34;priceCurrency&#34;: &#34;USD&#34;,


&#34;price&#34;: 38,
},]

 

EXPECTED

"offers": [
{
"image": "https:/in_1.jpg",
"priceCurrency" :"usd"
"price" : "38"
},]

some  decoding issue, from BE json is returning properly but in view page source issue is coming



Tethich
Community Advisor
TethichCommunity AdvisorAccepted solution
Community Advisor
November 11, 2024

Hi @user96222 

 

Try

"offers": "${product.offersjson @ context='unsafe'}"
Shashi_Mulugu
Community Advisor
Community Advisor
November 12, 2024