Need a Dynamic Breadcrumb Schema JSON-Ld script for shopify 2.0

Hi, I think I have figured it out. This is the code I tried now:

<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Hem",
"item": "{{ shop.url }}"
}
{% if template contains 'collection' %}
,{
"@type": "ListItem",
"position": 2,
"name": "{{ collection.title | escape }}",
"item": "{{ collection.url | prepend: shop.url }}"
}
{% elsif template contains 'product' %}
{% if collection %}
,{
"@type": "ListItem",
"position": 2,
"name": "{{ collection.title | escape }}",
"item": "{{ collection.url | prepend: shop.url }}"
}
{% endif %}
,{
"@type": "ListItem",
"position": 3,
"name": "{{ product.title | escape }}",
"item": "{{ product.url | prepend: shop.url }}"
}
{% elsif template contains 'page' %}
,{
"@type": "ListItem",
"position": 2,
"name": "{{ page.title | escape }}",
"item": "{{ page.url | prepend: shop.url }}"
}
{% endif %}
]
}
</script>