The query language adds a lot of flexibility when querying options for select, radio and checkboxes fields, for querying collections in Panel sections and to manipulate how information is displayed in the Panel.
If you are not familiar with Kirby's PHP API yet, you should learn more about it first. The query language is very close to it and will be confusing without the basics.
We recommend using double quotes around strings in the query language, otherwise it can result in the Panel throwing errors in some cases.
These are just a few examples. As you can see, it is very close to the PHP syntax. You don't need to relearn anything this way.
The query language is not limited to built-in methods. You can also use page models and custom methods within your queries.
There are two ways of using the query language in your blueprints:
1. To fetch data
In this example we use the query language to fetch options for a select field. You can fetch any collection of pages, files or users to be used as options.
2. To create string templates
Another way to use the language is to create custom information for page or file lists. In this case we use the query language as part of our template syntax.
In various field types (tags, select, multiselect, checkboxes, radio, files, pages and related custom fields) you can use the
query option to query possible options, for example:
Check out the docs for each of these fields in the Reference.
Queries can include arrays and nested method calls:
If you need to include quotes within strings, you can use the other quote type (
') or escape the quotes of the same quote type with backslashes:
Method calls (
parent.method(arguments...)) are supported if the parent is an object and the method exists (or if the object has a magic
__call() method) or if the parent is an array and the method is a PHP closure (anonymous function).
Property access (
parent.property) will behave like this:
- If the parent is an object, Kirby will first try to call a method with that name, then a magic
__call()method. If neither exist, Kirby will try to access a property with that name or call the magic
- If the parent is an array, the respective array element will be returned.
- Calling a property without any arguments (
parent.property()) is equivalent to accessing the property.