How to get pages (field) number

Hello everyone,

im new here and i dont find any solution.

On my blueprint there is a selction of pages (fields - you can add existing ones to selection). What i want from this field is a number in my frontend page.

What i tried: $page->pagesfield()->count(), $page->pagesfield()->num() or $page->pagesfield()->index()->num() and many many more. What i want: 2, 4 , 5, 8, (number of added pages)

All i got is an error or the url of these pages, not a single number
How can i achive this? Thank you, i think the solution is simple but i dont get it

Hey, welcome to our forum!

I assume you mean a pages field? To count the number of pages, you first create a pages object from the pages selected, then you can count them

$selectedPages = $page->pagesfield()->toPages();
$count         = $selectedPages->count();
1 Like

Thank you for your super fast reply! It worked, i knew it was simple.