The loop is populating more than just the specific collection I wrote to loop. I tried Can A Liquid For Loop Contain A Page Variable
Page Frontmatter
---
collection: criminal
---
Here is my config.yml setting up the collections:
config.yml
# Collections
collections:
practices:
output: true
permalink: /legal-practice/:title:output_ext
civil:
output: true
permalink: /legal-practice/civil-law/:title:output_ext
criminal:
output: true
permalink: /legal-practice/criminal-law/:title:output_ext
attorney:
output: true
permalink: /lawyers/:title:output_ext
collections_dir: collections
Criminal Collection
FS: /legal/collections/_criminal
- domestic-violence.html
- drug-offense.html
- dui.html
- xxx
Practices Collection
FS: /legal/collections/_practices
- civil-law.html
- criminal-law.html
- xxx
The file I'm accessing is /practice-law/criminal-defense/index.html
which has a front matter
definition of collection: criminal
The JSON+LD include defines a CollectionPage
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "CollectionPage",
"name": "{{page.title}}",
"mainEntity": {
"@type": "ItemList",
"itemListElement": [
{% for item in site[page.collection] %}
{
"@type": "article",
"name": "{{ item.title }}",
"@id": "{{site.url}}{{ item.permalink }}",
"about": { "@id": "{{item.wikidata}}" },
"mainEntity": { "@id": "{{site.url}}{{ item.permalink }}/#article" }
{% if forloop.last %} } {% else %} }, {% endif %}
{% endfor %}
]
},
"image":
{
"@type": "ImageObject",
"width": {{ page.img_width | default: site.img_width }},
"height": {{ page.img_height | default: site.img_height }},
"url": "{{ page.img_url | default: site.img_url }}"
},
"url": "{{ site.url }}{{ page.url }}",
"description": {{ page.summary | strip_newlines | strip | strip_html | remove: "\n\n" | jsonify }},
"mainEntityOfPage":
{
"@type": "CollectionPage",
"hasPart":
{
"@type": "SiteNavigationElement",
"xpath": "/html/body/nav"
},
"breadcrumb":
{
"@type": "BreadcrumbList",
"itemListElement":
[
{
"@type": "ListItem",
"position": "1",
"item":
{
"@id": "{{ site.url | append: "/index.html" }}",
"name": "Home"
}
},
{% assign crumbs = page.url | split: '/' %}
{% assign crumbs_total = crumbs | size | minus: 1 %}
{% for crumb in crumbs offset: 1 %}
{% if forloop.index == crumbs_total %}
{
"@type": "ListItem",
"position": {{ crumbs_total | plus:1 }},
"item":
{
"@id": "{{ site.url }}{{ page.url }}",
"name": {{ page.crumbtitle | jsonify }}
}
}
{% else %}
{
"@type": "ListItem",
"position": {{ crumbs_total }},
"item":
{
"@id": "{% assign crumb_limit = forloop.index | plus: 1 %}{% for crumb in crumbs limit: crumb_limit %}{{ crumb | append: '/' }}{% endfor %}",
"name": "{{ crumb | replace:'-',' ' | upcase }}"
}
},
{% endif %}
{% endfor %}
]
}
}
}
</script>
Results
What is being looped, instead, is the array of FS: /legal/collections/_practices
instead of _criminal. The JSON loop target changes on each page of any collection that contains an item list. Such is the case for _criminal
. I'll continue to make the `JSON+LD valid. I'm just stuck at the for loop. The Google Structured Data Testing Tool shows a loop of articles from the _practices collection instead of _criminal. https://search.google.com/structured-data/testing-tool#url=https%3A%2F%2Flegaldemo.strikehawk.com%2Fpractice-law%2Fcriminal-defense%2Findex.html