Use array of structure field entries in blueprint query language


#1

Hi everyone,

I have pages to store bibliographic data of books etc. On each page there is a structure field to add multiple authors.

I now want to show these authors in the info text of a pages section. I was thinink about something like page.authors.toStructure.pluck('lastname') but I am not sure is this is possible at all.

Thank you a lot for your help!


#2

pluck() returns an array, but you need a string. Should be possible with a custom method that returns a string, though.


#3

Thank you!
Could you give me a hint how to get started with a custom method?


#4

Sure, there’s an entire section in the docs dedicated to that: https://getkirby.com/docs/reference/plugins/extensions/page-methods


#5

As a beginner I am not sure, if this is perfect, but it works so far.

  'implode' => function ($structureField, $key) {
    $array = $this->$structureField()->toStructure()->pluck($key);
    return implode(" / ", $array);
  }

I will add if statements to check for the fields.

Any comments for improvement are appreciated!