So, I’m creating arrays of articles from different content sections of the site. Some sections have articles broken out into grandchildren, consequently there are no ‘children’ that are articles there.
I’d like to add up all the articles throughout the site onto the homepage, but also in curated sections.
Here’s the structure:
/content/section1 // has no children ......../section2/articles ......../section3/articles ......../grandsection/section4/articles ...................../section5/articles
And here are the collections I’d like to create an array to include all children but not children that are sections (such as #4 or #5), just the children of those sections.
I’m thinking I need to do it this so that I can reference these article arrays in snippets as well, otherwise I’d need to redefine those $articles arrays in the snippets, too (DRY, etc.).
Solutions
A. Use Controllers — may allow merging of arrays already defined in the site controller, correct? Controllers | Kirby CMS
B. Use Collections — each Collection file would define a collection, but could it allow merging of collections? Collections | Kirby CMS
Also, can I reference a Collection inside another collection.php?
Another question: Could I also just index the entire site and get all entries using the article template?
Edit: I see it: $articles = $site->index()->filterBy('template', 'article');
You can use $site->index() but I hope you’ve seen the warning. It’s no problem on smaller site, but on big sites, you can run into serious performance issues.
Yes, you can fetch a collection anywhere using the collection() helper or kirby()->collection().
dump() is a helper function, Kirby’s alternative to PHP’s var_dump(), which in turn is simple way of inspecting a variable. Good for quick checks what you get back, not really the best way to actually debug your code.