# Related content on the panel

**URL:** https://forum.getkirby.com/t/related-content-on-the-panel/32231
**Category:** Questions
**Created:** [August 12, 2024, 8:52am UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231 "2024-08-12T08:52:53Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![javiercuello](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@javiercuello](https://forum.getkirby.com/u/javiercuello)
#### Post date: [August 12, 2024, 8:52am UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/1 "2024-08-12T08:52:53Z")

</div>

I’m trying to achieve something similar to related pages on the panel. I checked the documentation and I’m still not quite sure how to come up with a proper query. This is my scenario:

1. I have a job offer page
2. I have a company page
3. From the job offer page, I can select a company page

Now, what I would like to do is in the company blueprint, automatically display job offers that have that company selected in the company field.

For reference, this is how the job blueprint looks like in this regard:

```auto
    fields:
      company:
        label: Company
        type: pages
        query: site.find('companies')

```

According to my gpts, “this is a complex data relationship and Kirby wasn’t made for that”. So I wanted to validate this feedback.

The important bit is to display these job offer pages automatically from the company page in the panel, not via manual selection.

---

<div class="post-metadata">

### Author: ![moonwalk](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@moonwalk](https://forum.getkirby.com/u/moonwalk)
#### Post date: [August 12, 2024, 8:59am UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/2 "2024-08-12T08:59:52Z")

</div>

You can use a pages section with a query that filters all job offers by the company field.

---

<div class="post-metadata">

### Author: ![javiercuello](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@javiercuello](https://forum.getkirby.com/u/javiercuello)
#### Post date: [August 12, 2024, 9:10am UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/3 "2024-08-12T09:10:33Z")

</div>

Thank you. I’ve been trying something like this, to no results.

```auto
  related:
    label: Related Pages
    type: pages
    query: site.find('jobs').filterBy('company', $page->id())

```

Logic is that in children of “jobs”, find the ones that share the same id than the current page. But that doen’t seem to be working to retrieve anything.

---

<div class="post-metadata">

### Author: ![moonwalk](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@moonwalk](https://forum.getkirby.com/u/moonwalk)
#### Post date: [August 12, 2024, 9:12am UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/4 "2024-08-12T09:12:39Z")

</div>

> [@javiercuello](#):
>
> `$page->id())`

you cannot use php syntax inside blueprints, also, a pages field stores the uuid, not the id

---

<div class="post-metadata">

### Author: ![javiercuello](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@javiercuello](https://forum.getkirby.com/u/javiercuello)
#### Post date: [August 12, 2024, 9:22am UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/5 "2024-08-12T09:22:58Z")

</div>

> [@moonwalk](#):
>
> uuid

Thank you. I will keep exploring. Nothing I have tried seems to be working, and I haven’t found any other examples / documentation so far. Will keep digging.

---

<div class="post-metadata">

### Author: ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)
#### Post date: [August 13, 2024, 11:41am UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/6 "2024-08-13T11:41:58Z")

</div>

The main problem is that the pages field might store references to pages in many formats.  
A job might save its reference to the company in any of the following formats (in the content txt file):

```txt
Company: companies/fuller-design-systems

```

```txt
Company: 
  - companies/fuller-design-systems

```

```txt
Company: 
  - page://kasje23j90032dnm0xnd320

```

(or possibly more combinations).

So there is no straightforward way to filter pages by their reference to a page, as those references first need to be dereferenced to actual page objects.

I’d suggest you create a [Page Model](https://getkirby.com/docs/guide/templates/page-models) for the Job pages. Page models help you customize the functions that a certain type (aka template) of pages offer, then you can filter by the result of that function.

For example this could look like this:

**site/models/job.php:**

```php
<?php 

use Kirby\Cms\Page;

class JobPage extends Page {
    /**
    * Dereference the company field
    */
    function companyPage(): ?Page {
        return $this->company()->toPage();
    }
}

```

Then you can filter by that function

```yml
query: site.find('jobs').children.filterBy('companyPage', page)
# ^^^^^^^^^ ^^^^ ^^^^

```

PS: Notice you also need to call `filterBy` on **the children** of `site.find('jobs')` and not directly on the “jobs” page itself.

---

<div class="post-metadata">

### Author: ![javiercuello](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@javiercuello](https://forum.getkirby.com/u/javiercuello)
#### Post date: [August 13, 2024, 3:40pm UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/7 "2024-08-13T15:40:59Z")

</div>

Thanks @rasteiner ! I didn’t know about Page Models. This is pretty much what I wanted. What I’m not sure if it’s possible in Kirby is to avoid the select modal step, and have those pages displayed directly (without the manual association).

I’m not sure if that makes sense, from the tool’s point of view — although would be helpful to me.

---

<div class="post-metadata">

### Author: ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)
#### Post date: [August 13, 2024, 3:54pm UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/8 "2024-08-13T15:54:13Z")

</div>

That sounds like you’re not using a pages **section** , but a pages **field**.  
In the company page blueprint you should be using a pages section.

```yml
title: Company

columns:
  main:
    width: 2/3
    sections: 
      fields:
        type: fields
        fields:
          info:
            type: info
            text: Here are your fields
  aside:
    width: 1/3
    sections:
      jobs:
        label: Jobs
        type: pages
        query: site.find('jobs').children.filterBy('companyPage', page)
        create: false

```

* * *

However, rethinking the whole situation, it sounds like you have a “one to many” relationship here (many job offers belong to only one company, I think). Therefore it could make sense to have the job offers be children of the company pages. That would kind of make it easier, I think.

---

<div class="post-metadata">

### Author: ![javiercuello](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@javiercuello](https://forum.getkirby.com/u/javiercuello)
#### Post date: [March 4, 2025, 7:50pm UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/9 "2025-03-04T19:50:11Z")

</div>

@rasteiner What you mentioned makes sense, I could have company pages, and jobs are child of a respective company — since a company can have multiple jobs.

However, I’m struggling to follow this approach in implementation, since I understand that child pages cannot be created from a company’s blueprint.

Should I have both `/jobs` and `/companies` at the same level in the content folder, and then just link a company to a job?

I understand that in that case, from the company’s page I would only be able to list “linked” jobs and not do anything else.

Am I correct?

---

<div class="post-metadata">

### Author: ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)
#### Post date: [March 4, 2025, 7:59pm UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/10 "2025-03-04T19:59:22Z")

</div>

> [@javiercuello](#):
>
> Should I have both `/jobs` and `/companies` at the same level in the content folder, and then just link a company to a job?

That was the idea of the suggested approach, yes.

> [@rasteiner](#):
>
> ```auto
> sections:
> jobs:
> label: Jobs
> type: pages
> query: site.find('jobs').children.filterBy('companyPage', page)
> create: false
> 
> ```

This section would then list all job children which are linked to the current company.

---

<div class="post-metadata">

### Author: ![javiercuello](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@javiercuello](https://forum.getkirby.com/u/javiercuello)
#### Post date: [March 4, 2025, 8:19pm UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/11 "2025-03-04T20:19:14Z")

</div>

@texnixe

Would there be any caveats from creating a job as hierarchical child of a company? I thought this was not possible, but I just tested this in my company blueprint:

```auto
title: Company page

columns:
  main:
    width: 2/3
    sections:
      jobs:
        type: pages
        template: job

```

That creates this in my content folder

```auto
/company/job 1/job.txt

```

As a side note, on my `home.php` template later on I’ll need to display all jobs across companies by date they were posted, so I’m curious if either approach will make that more or less convenient.

---

<div class="post-metadata">

### Author: ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)
#### Post date: [March 4, 2025, 8:35pm UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/12 "2025-03-04T20:35:01Z")

</div>

Yes, that’s also possible, of course. Whatever structure suits your project best. It doesn’t matter if you sort all children of a page called jobs, or of a collection of pages fetches from all the company pages, as long as the pages have a date.

---

<div class="post-metadata">

### Author: ![javiercuello](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@javiercuello](https://forum.getkirby.com/u/javiercuello)
#### Post date: [March 5, 2025, 10:22am UTC](https://forum.getkirby.com/t/related-content-on-the-panel/32231/13 "2025-03-05T10:22:47Z")

</div>

I understand. I appreciate your help and support as I continue learning Kirby. I will experiment with these approaches. Thank you!
