I’m using the same layout for pages in different categories and wondering if there is a way to call object page.categories from the front matter in for loop.
{% for page in site.collection limit:3 %}
{% if page.categories contains ‘{{ page.categories }}’ %}
Your first issue is that your variables are colliding as names.
Page is already a variable.
So use p or collection_page or item.
{{ page.categories | inspect }} Categories of current page
{% for p in site.collections %}
{{ p.categories | inspect }} categories of current item
{% if p == page %}
...
What are you trying to achieve? In terms of the frontend result of displaying collections and categories? You might be able to do something similar using site.categories.
Code
Your comparison of categories seems weird with the quotes as that will not evaluate.
Plus it’s bad a idea to check if an array contains another array or hash. Try displaying an object to understand it before you use it.
Plus categories are not supported in collections, which I cover more on below.
Note that collections cannot have categories in the usual sense. Only posts can. Well, posts is also a collection, but other collections won’t have categories.
Yes you can set categories on any page like a collection. But it will not add to the grouping of all categories in site.categories.
Further, a post will convert this string implicitly in Jekyll to an array
categories: abc def
# to
categories:
- abc
- def
While any non-posts that have categories won’t get that benefit. You’ll have to be explicit with the array form.