Hey there,
Is there a Kirby variant of var_dump or print_r for collections?
Whenever I use the native PHP functions it outputs what seems to be the whole Kirby index and not the data I’m expecting.
For example:
<?php print_r( $page->images() ); ?>
Doesn’t print just an object of images objects. Like I said it prints a whole bunch of stuff not directly related to the current collection.
Thanks
If you are only interested in what images are contained in the collection, you can use the following:
<?php print_r($page->images()->keys()); ?>
This also works for page collections:
<?php print_r($page->children()->keys()); ?>
2 Likes
Completely missed that in the docs! Thanks!
jevets
4
Worth mentioning here, there’s also collection::toArray()
and collection::toJson()
, which can help make the dump more readable.
http://getkirby.com/docs/toolkit/api#collection
2 Likes