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
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
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() ;?>
->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”
hmm, it still not working
$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
$memberID must be a string, so you will have to use
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:
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
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: https://getkirby.com/docs/panel/blueprints/options