Access data method in page

Hi !

I’m working on a Kirby project with a page A where users can check criteria (via checkboxes, basically, it’s a form). When they load page A, it creates an instance of page B. When they check criteria, it writes the information in the .txt file of the instance of page B. Criteria are defined based on site.yml (it’s a small database).

eg of page B instance .txt file. Here, “Critere-12” has been checked:

Title: Your project


Critere-12: 12

When I display page B, I want to know which criteria have been check to display it.

My issue is that I don’t understand how to access to the method of Critere-12 (in this example).

I tried several PHP methods, which don’t work:

if($page->critere_12()) {echo "it works!";}
// or
if($page->critere12()) {echo "it works!";}
$id = $criteria->id();
if(method_exists($page, "critere_{$id}")) {echo "it works!";}

Nothing works… I don’t understand how to access Critere-12… Can you help me with this issue?

Thanks a lot!

This is correct in regard how to access the field, but the if statement isn’t, because it will always return true, no matter if the field exists or is empty.

So the correct way to check for an existing field would be

  if($page->critere_12()->exists()) {echo "it works!";}

1 Like

Oh great! You solve my problem. Thanks a lot :slight_smile: !