Table layout: output resolved page titles of multiple slug values of a checkbox field

Hey there!

I just got my feet wet with Kirby 4 and I’m very pleased by the amount of things that are possible with it. Great work!

I have a question regarding table layout columns, the solution of which I couldn’t research or puzzle together from other people’s questions and code snippets. The table prints out one row per page. Each page’s template has a checkboxes field configured who’s options consists of pages of another type - in order to build a relation between the two:

        label: AG(s)
        type: checkboxes
          type: query
          query: site.children.template("workgroup")

A field entry in a page would appear like this:


Workgroups: ag-page-99wh4xvyziip0fev, ag-page-mcinhkzc65fwccwe


Now, what I would love to have is a column in my layout table, which instead of showing me the slug of the selected pages (e.g. ag-page-99wh4xvyziip0fev ag-page-mcinhkzc65fwccwe) would instead show me their human readable titles. But I can’t figure out if and how that might be possible via query syntax. This is what I’m fiddling around with right now:

    type: pages
    layout: table
        label: AGs
        value: "{{ page.workgroups }}"

I fiddled with .pluck() and toPages() and whatever else in my value query, but things never changed for the better. I probably didn’t really get them.

Thanks in advance for your help!


I’m not sure if there is an out of the box way.

What you can do, however, is create a custom page method (e.g. getWorkgroups()) that returns a list of titles from the pages collection stored in the field.

Then use this custom method in your column:

        label: AGs
        type: html
        value: "{{ page.getWorkgroups() }}"

Thank you Sonja! These custom page methods also appeared as term in my searches. I will try that out and give you feedback how that turned out. Already good to know that I don’t need to bother any longer with query language acrobatics.

Just in case, can be something simple like this:

'pageMethods' => [
	'getWorkshops' => function() {
		$html = '<ul>';
		foreach ($this->workshops()->toPages(',') as $p) {
			$html .= '<li>' . $p->title() . '</li>';
		$html .= '</ul>';
		return $html;
1 Like

Hey Sonja, your suggestion worked out perfectly. Thank you! :partying_face:

1 Like