How to use number of pages for paginate as variable?

I want to have setting in panel how many inner pages to show on page. I am using field “pgn”. I imagine it should work like this, but it doesn’t. Is it possible to print value in paginate(____) as variable?

<? $pgn = $page->pgn() ?>

<?php $children = $page->children()->sortBy('date','desc')->paginate($pgn) ?>

<?php $pgn = $page->pgn()->toInt() ?>
1 Like

Thank you, didn’t think about it, as <?= $page->pgn() ?> prints number well.

Yes, that is because when echoed, the field object which is returned from $page->pgn() is converted to a string (via the magical __toString() method). But if you don’t echo, you have a field object and you cannot pass that to the paginate() method.

By the way, in version 3.7.0-rc.1 /page:2 etc. are returning as page not found.

Yes, thank you, there is already an issue on GitHub:

1 Like