Conditionals in the yml query language?

I’m trying to put some text on the screen with a query like this in my yml:

text: '{{site.find(page.parent.uid).index.filterBy("autoid", page.department).getField('title')}}'

This works just fine most of the time, but when page.department is empty, I end up with the wrong title.

I was hoping conditionals were possible in this “language”, but I can’t find the name of the language nor any reference to it anywhere in the Kirby docs.

So I guess I have 3 questions:

  1. What is this language?
  2. Where can I find docs for this language?
  3. Are there conditionals in this language, and if so what is the syntax?

Here’s what I tried which didn’t work:

  • text: '{{page.department ? site.find(page.parent.uid).index.filterBy("autoid", page.department).getField('title') : ""}}'
  • text: '{{page.deparment && site.find(page.parent.uid).index.filterBy("autoid", page.department).getField('title')}}'
  • text: '{{r(page.department, site.find(page.parent.uid).index.filterBy("autoid", page.department).getField('title'), "")}}'
  • text: '{{e(page.department, site.find(page.parent.uid).index.filterBy("autoid", page.department).getField('title'), "")}}'

I suppose I could try more things, but it’s just incredibly frustrating to have to stab wildly in the dark like this, so I’m really hoping I can just find some docs for this mysterious language.

Thanks for any pointers

We call it query language and the documentation is here: Query Language | Kirby CMS

It doesn’t support complex logic, so your best bet is a custom method that you can then use in the query language.

Ah yes, that’s what I was looking for. Perhaps this could be included with the rest of the docs on the reference page?

Also, now that I have the docs, the only thing I’m seeing there about custom methods is the following sentence:

The query language is not limited to built-in methods. You can also use page models and custom methods within your queries.

Are there any docs about these custom methods? With that sentence alone I don’t know where to start!

Yes, of course, it’s all in the Extension reference: Extensions | Kirby CMS