Can i create a page object from a uri-string in plugin that extends fieldmethods?

Is it possible to create a page object from a uri-string in a plugin that extends fieldMethods. I want to preview in pagetable plugin the streetname of a specific client.

in my blueprint (with pagetable plugin)

    columns:
        myclient:
           label: myclient
           type: text
           text : '{{ page.myclient.setAdres}}
    // site/plugins/my-methods/index.php
    Kirby::plugin('your/plugin', [
        'fieldMethods' => [
                'setAdres' =>function($field){ 
                     $klanturi=$field->value(); // clients/client1
                    $clientpage=  page($klanturi);
                    return $clientpage->streetname();      // i get error $clientpage  is null
               }
        ]
    ]);

my error: Call to a member function streetname() on null

You must check if the page exists:

    Kirby::plugin('your/plugin', [
        'fieldMethods' => [
                'setAdres' =>function($field){ 
                    $klanturi=$field->value(); // clients/client1

                    if($clientpage = page($klanturi)) {
                      return $clientpage->streetname();      // i get error $clientpage  is null
                    } else {
                      return "No Streetname";
               }
        ]
    ]);

Never call any class method without prior checking if you have an object of that class…

the page exists, it works when i use $clientpage= page(“clients/client1”), but it doesn’t work with the variable: $clientpage = page($klanturi). I guess the variable has the wrong format?
When i test with: return $klanturi, then i see ‘clients/client1’ as a result.

Yes, it’s a good practice to check if the page exists.

ok, it works now! The check did the trick, there was 1 wrong field.