Get current page title in a panel query

Hi there,

I’m having trouble with something that may be a bit silly…
Is it possible to get the title of my current panel page in a query? And how?

For example, if the title of my page is “John Doe” :

    sections:
      filmsprod:
        type: pages
        label: Films produits par {{ page.title }}

Here it works, I’ve got “John Doe”. But not when I make a query (and I can understand why) :

        parent: site.find("films")
        query: page.childrenAndDrafts.filterBy('prod', '{{ page.title }}')
        template: film

But how could I get this?

        query: page.childrenAndDrafts.filterBy('prod', 'John Doe')

Many thanks,

Elba

Try

query: page.childrenAndDrafts.filterBy('prod', page.title)

Hi and thank you texnixe,
I’m sorry I didn’t specify, but I’ve also tried (‘prod’, page.title) and it doesn’t work for me.

The question is how this query makes sense. Because page in this context refers to the current page item within the section. But I guess you want to filter by the current page’s title?

query: page.childrenAndDrafts.filterBy('prod', kirby.page.title)

Not tested. But kirby.page should return the current page.

It doesn’t work, perhaps a problem with the formatting of the title but I can’t explain it yet. When I manually enter the name that corresponds to the page title, it works fine though… Il also tried, without success :

query: page.childrenAndDrafts.filterBy('prod', kirby.page.title.value)

I’m still thinking.

Maybe provide a bit more context, not sure what refers to what here regarding those code snippets.

I have a set of ‘film’ pages (children of the ‘films’ page), including a multiselect field ‘prod’, which gets the team members, entered in a structure on another page (‘apropos’).

film.yml (site/films/film) :

title: Fiche film
(...)
          prod:
            label: "produit par"
            type: multiselect
            options:
              type: query
              query: site.find('apropos').equipe.toStructure
              text: "{{ item.nom }}"
              value: "{{ item.nom }}" // John Doe

film.fr.txt (site/films/film) :

Title: Alias

----

Prod: John Doe

----

For a new feature, I’ve created a page for each member of the team (site / cv / cv-prod). On each page, I want to display only the films produced by that member (i.e. when the ‘prod’ value matches the page title). This works fine when I test directly with the name : query: page.childrenAndDrafts.filterBy(‘prod’, ‘John Doe’), but not when I try to query the current page title.

cv-prod.yml (site/cv/cv-prod) :

title: Page producteur

columns:
  - width: 3/3

    sections:
      filmsprod:
        type: pages
        label: Films produits par {{ page.title }} // Films produits par John Doe
        parent: site.find("films")
        query: page.childrenAndDrafts.filterBy('prod', kirby.page.title) 
        template: film
        status: all

cv-prod.fr.txt (site/cv/cv-prod) :

Title: John Doe

----

Text: Test

----

Uuid: 3PsPBXuxv31S9XBY

I’ve done it without any prob on the frontend, but on the panel I can’t manage it.

cv-prod.php (controller) :

$filmsprod = page('films')
    ->children()
    ->listed()
    ->filterBy('prod', $page->title())
    ->sortBy('date', 'desc');

$nomprod = $page->title()->value(); // gets the current page title, which I can't do from the panel

$ficheprod = page('apropos')
        ->equipe()
        ->toStructure()
        ->findBy('nom', $nomprod);

Also, without adding ‘value()’ for $nomprod, I couldn’t get any data from $ficheprod.

Sorry, I’m not sure I’ve given you any useful information…

I’m a bit surprised that this works with the hard-coded name.

Because I think, page.title was actually correct, but not page.childrenAndDrafts, but that it should be page('films').childrenAndDrafts().filterBy('prod', page.title()). Because the pages to filter are not the children of the current pages, but the children of the films page where the prod field is located.

Oh ok, that was so simple… I think I misunderstood this line

parent: site.find("films")

And yet it really worked with the hard-coded name…

It’s been a while since I’ve looked at my Kirby site… I need to get back into the documentation seriously.

Thank you so much for your time and patience.