Refer to a certain structured field in a custom block on a certain page

I have been struggling with this for too long now, so pardon me but i bet you can help me easily.

I have a page “investor-relations/fika” with a custom block of the type “financial calendar”. In that block there is a structured field called “items”. I want to make a collection of that data so that i can use it in other places on the site.
What i tried is:

$fika = $site->find('investor-relations/fika')->blocks()->toBlocks()->filterBy('type', 'financial-calendar')->first()->items()->toStructure();

$fika = $site->find('investor-relations/fika')->blocks()->toBlocks()->findBy('sid', 'fika')->items()->toStructure();

But they end in “NULL” , what am i doing wrong?
It’s the only block of that type on the page and it has a field “sid” with the value “fika”.

Any hints?

This looks correct. What I’d do is debug this step by step, e.g. dump this part first

$site->find('investor-relations/fika')->blocks()->toBlocks();

Then add the filter, the first etc.

1 Like

Oh my… i found the mistake. The field with the blocks is called “segments” not “blocks”… In the query i just didn’t realize that in this part it’s the name of the field rather than a method. My bad.

$fika = $site->find('investor-relations/fika')->segments()->toBlocks()->filterBy('type', 'financial-calendar')->first()->items()->toStructure();

this seems to work, now. Thank you again!