I’m experiencing a funny problem when using toStructure()
coupled with a callback filter()
function.
My data structure is as follows:
Title: Forum Users
----
Users:
-
user: user1
key: >
3e0c7b3706538eb211e40c04xlemfeflf1r3errgrgrgglrmeglregmrlgmgldgmdglkmd
-
user: guest
key: >
xlemfeflf1r3errgrgrgglrmeglregmrlgmgldgmdglkmde503c3bc806e3
If I try a code like this:
$usr_key = page('forum-users')->users()->toStructure()->filter(function ($usr) {
return $usr->user() == 'guest';
});
echo $usr_key;
I get back 1
. I can’t do $usr_key->key()
as there is only 1
as a string value.
If I do it “manually” like this
$usr_key = '';
foreach(page('forum-users')->users()->toStructure() as $usr) {
if ($usr->user() == 'guest') {
$usr_key = $usr->key()->value();
};
};
echo $usr_key;
I get back the actual value (xlemfeflf1r3errgrgrgglrmeglregmrlgmgldgmdglkmde503c3bc806e3
).
I haven’t been writing Kirby code in a while and can’t figure what I am missing out.
I tried first with a simple
page('forum-users')->users()->toStructure()->filterBy('user', 'guest');
and also get back 1
.
Any help highly appreciated! (: