Can i use filterBy on a structure field?

For example like this:

$pages->find(“my-uri”)->children()->visible()->filterBy(“structurefield.number”, “>”, 0);

My structure field looks for example like this:


number: 20
text: test

number: 30
text: test

There is a new toStructure method you can use to transform YAML to a Kirby collection:

$structure = $page->structurefield()->toStructure();

Edit: Sorry, I haven’t properly read your question. You can use the filter method to filter a collection by a callback method.

$collection = page('my-uri')->children()->filter(function($p) {
  $structure =  $p->structurefield()->toStructure();
  return $structure->number() > 0;

Shouldn’t it be

$structure = $page->structurefield()->toStructure();

If you use the new method, you get a nice object, that you can access like all Kirby objects, e.g. to get the value of the number field within your structure field:


Yep, you’re right. I shouldn’t write posts when I’m too tired :wink: