Expand my Community achievements bar.

SOLVED

HTL issue

Avatar

Level 4

 

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

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi @user96222 

 

Try

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

View solution in original post

4 Replies

Avatar

Community Advisor

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

<scripttype= 

Avatar

Level 4

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



Avatar

Correct answer by
Level 7

Hi @user96222 

 

Try

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