Get the page object from a given field value

Continuing the discussion from AutoID Plugin (create unique page ids):

is there a way to achieve the page object from a given field value?

I like to use the autoId plugin from @helllicht which autocreate a unique ID for each entry.

    label: Related Projects
    type: checkboxes
    options: query
        fetch: siblings
        value: '{{autoid}}'
        text: '{{title}}'

Then I would like to output the related page as a page object to have access to all field items.

<?php $member = $child->relatedprojects()->toPage() ?>
<?php echo $member->title() ;?>
<?php echo $member->local_adress() ;?>

That was possible when I used url as query value

options: query
    fetch: siblings
    value: '{{uri}}'
    text: '{{title}}'

Is there another way to achieve the page object?

You could use find:

$member = $page->siblings()->findBy('id', $value);

Thanx texnixe for fast reply,
But it’s not working, I have it like this:

<?php $memberId = $child->member(); ?>
<?php $member = $child->find('autoid', $memberId); ?>
<?php echo $member->title() ;?>

For the ->find() method has the page to be in the same page collection?

What is $child in your example? It needs to be collection; since you are fetching related pages from the page’s siblings, you have to search for the page in the same collection.

It is the home page witch shows some featured events:

<?php $children = $pages->find('aktuell')->children()->visible() ?>
<?php if($children->count()) : ?>
<ul class="pure-g thumbs">
<?php foreach($children as $child):  ;?>

In each event I have the ID queried from a related member to fetch the name, the adress … and so on.
So, the the related pages are in different folder

So, “Traces of Memory” is one such event, right? And which of the pages in the tree could then be a related page? Any?

Any member in netzwerk could be related. The member are mostly also the organizer of an event.

Then you should be able to get the right page by querying the grandchildren of “Netzwerk”

page('netzwerk')->grandchildren()->findBy('id', $value());

hmm, it still not working

<?php $memberId = $child->member(); $allmember = $pages->find('netzwerk')->grandChildren(); //$allmember does output the list of grandchildren $member = $allmember->find('autoid', $memberId); ?>

is it correct ->find('id', $memberId) or ->find('autoid', $memberId) – both is not working?!

What is the name of the field that contains the autoid? If it is called “autoid”, use autoid.

$memberID must be a string, so you will have to use $child->member()->value().

1 Like

:grinning: Now it works! But with ->findBy() and I changed



<?php $member = $site->index()->findBy('autoid', $child->member()->value()) ;?>

I hope there is no performance loss by searching the whole index or is it better to delimit the search?
Thanx a lot for your help! @texnixe

Yeah, you are right, should of course have been findBy(), I corrected it above.

Searching the whole index can take a while for large sites, so it’s indeed recommended to exclude all pages that you know won’t match (meaning: only include those you know can match):

Like Sonja wrote:

page('netzwerk')->grandchildren()->findBy('autoid', $child->member()->value());
1 Like

I thought so. That was it all about: to use the AutoId plugin, to avoid calling the path, if some name will change for seo reasons or so. But I guess the main folder naming should consist for a while…
I wrote it now like Sonja – I didn’t knew that I could write page('somepage') instead of $pages->find('somepage').
I learned so much again. thanx for the great support!
Is there a way to protect the url in the panel?

In Kirby 2.3 their will be an blueprint option for that:

That sounds good to me! :relaxed: