Returning a boolean in a blueprint with Kirby Query Language

Hi guys — I’ve got one I think I’m close to figuring out, but just can’t quite get it (or maybe I’m way off lol).

I’m building a site for an online graduation show. Each student (there are 150) will have their own page, and should be able to log in to the panel and see (and edit) only their page. The way that I think this can be done is to write a custom page method, then use it within the blueprint to check the current user’s email against the email field in the page to decide whether the page should be visible.

My main issue is that while I can correctly return true / false and echo it as a string, it doesn’t work as a boolean.

Here’s where I’m at:

#student.myl

title: Student
preset: page

options:
  read:
    admin: true
    student: {{page.checkPermission(page.email)}} #this should return true / false

pages:
  template: default

fields:
  contentheadline:
    label: Content
    type: headline
    numbered: false
  email:
    type: email
    disabled: true
  testfield:
    label: Test Select
    type: text
    help: "{{page.checkPermission(page.email)}}"
    # this field is just to check the response from my custom method, which is working as expected

And the custom page method:

<?php
// check-persmission/index.php
    Kirby::plugin('jackfowler/check-permission', [
        'pageMethods' => [
            'checkPermission' => function ($pageEmail) {
              if(kirby()->user()->role() == 'admin'){
                return true;
              }
              else if($pageEmail == kirby()->user()->email()){
                return true;
              }
              else{
                return false;
              }
            }
        ]
    ]);

I’m not sure query language works there at all.

But another way of doing this is described here:

Haha woops ok cool! This looks like a much better approach, thank you @texnixe , I’ll give it a go.

Thanks, this worked perfectly :+1:

Thanks for reporting back!