Trouble with query site.find().children from block

Hello,
I try to have something working like @plagasul suggested here
Here my structure, on the first level of the site I’ve got a children agents with agent pages inside. I try to call those agents from a page production with a block with this blueprint called listeagents.yml

name: Liste d'agents
fields:
  agent:
    type: tags
    layout: list
    options: query
    query: site.find('agents').children

the code to print the agents

<?php foreach ($block->agent()->split('|') as $agent): ?>
  <h3><?= $agent ?></h3>
<?php endforeach ?>

but then I got the agent printed like: agents/agent1, agents/agent2
How to have juste the name of the agent and not the structure with the parent (agents) / and the name (agent1) ?
Thank you for your help.

I’m a bit surprised that splitting by | works here, because the default separator is a comma, not a pipe.

But what you would have to do to fetch the children, would be to convert the field value to a pages collection,



<?php foreach ($block->agent()->toPages(',') as $agent): ?>
  <h3><?= $agent->title() ?></h3>
<?php endforeach ?>
1 Like

Thank you @texnixe it works to catch all agents that have a page in the agents parent, but only those, it doesnt catch all the agents that are introduced int the articles page as type:tags that have a page and don’t have a page yet.
What I try to achieve is what @plagasul do with:

<?php $artists = $page->artists()->split(); /* Get artists from tag field as comma separated list */?>
<?php foreach ($artists as $artist): /* For each artist */?>
	<?php if (page($artist)): /* If there is a page with that id */ ?>
		<?= page($artist)->title()->html() ?> belongs to the gallery.
	<?php else: ?>
		<?= $artist ?> does not belong to the gallery.
	<?php endif ?>
<?php endforeach ?>

Must say I don’t understand.

Thought it was about getting the pages selected in this tags field.

Maybe I didn’t understand what is proposed on this page General question on the logic of a kirby website - #5 by KrsBee
I thought that artists with pages are pulled up from the artists page, and artists without pages are add directly in the current page as tag.
Sorry for my confusion.

Ah ok, I didn’t read the full context of the other threads. So this is about tags that can exist as children of the agents page, but it is also possible to add additional strings that are not pages.

So the equivalent of the above would be:

<?php $agents = $block->agents()->split(); /* Get artists from tag field as comma separated list */?>
<?php foreach ($agents as $agent): ?>
	<?php if ($p = page($agent)): /* If there is a page with that id */ ?>
		<?= $p->title()->html() . ' is a child of the agents page' ?>
	<?php else: ?>
		<?= $agent . ' is just a string' ?>
	<?php endif ?>
<?php endforeach ?>
1 Like

Thank you very much.