core
core copied to clipboard
pager() throws an error when used on homepage
When using the pager function, together with setcontent on the homepage (root url /
) this error is thrown:
Details
Question | Answer |
---|---|
Relevant Bolt Version | 5.0 |
Install type | Composer install |
PHP version | 7.4 |
The error happens at https://github.com/bolt/core/blob/9eb9a607d89d54d936a0cd0abba6ef7336e0cdf5/src/Twig/ContentExtension.php#L480-L483
where $this->requestStack->getCurrentRequest()->get('_route_params')
returns null
when on the homepage
I think it does work, if you tell it what to use for paging. In your case {{ pager(records) }}
.
Thanks for the quick feedback @bobdenotter
Unfortunately, this results in the same error:
It works for me, strange:


Can you close Exception "1" (the 'minus' on the right) and see what Exception "2" says?
I had the same error. Not using I was using homepage: customType
in config.yaml. Switching back to homepage: homepage
and changing the template fixed it for me
Hey @Marmelatze, could you share a reproducible example? I'd be happy to take a look and see if there's a bug we can fix :-)
Sorry for the delay. Example repo: https://github.com/Marmelatze/bolt-test (only change to default install is the last commit)
Without the pager in listing.twig
it works fine.
A similar problem when I did according to the instructions https://bolt.tips/entry/how-to-build-a-personal-blog-with-bolt-cms-in-wonder-30-Minutes Made a small check at \vendor\bolt\core\src\Twig\ContentExtension.php
public function pager(Environment $twig, ?Pagerfanta $records = null, string $template = '@bolt/helpers/_pager_basic.html.twig', string $class = 'pagination', int $surround = 3)
{
$params= $this->requestStack->getCurrentRequest()->get('_route_params');
if ($params === null) {
$params =[];
}
$params = array_merge(
//$this->requestStack->getCurrentRequest()->get('_route_params'),
$params,
$this->requestStack->getCurrentRequest()->query->all()
);
Hi @dbeerten ,
I've tried to reproduce this as well on Bolt v5.1.9 and I don't get the same result.
Have you tried updating your Bolt project? Is this still happening to you?
@nestordedios I fixed it by using this workaround from @Marmelatze
I had the same error. Not using I was using
homepage: customType
in config.yaml. Switching back tohomepage: homepage
and changing the template fixed it for me
Since there's a fix won't it be cool if this issue is closed? @dbeerten
Sorry to revive this, but I would ask that this not be closed as this appears to be a bug.
My homepage setting in the config is set to 'entries' (which a comment in the config specifically notes is allowed) with the template being listing.twig. I receive the same array_merge error as shown at the start of this thread. I am running Bolt 5.1.19. Per the workaround mentioned above, restoring the homepage singleton and setting the homepage to that does fix things.
To my understanding, however, a 'homepage' singleton contenttype is not a requirement. As such, while this may be a sufficient temporary workaround, I feel it should be addressed as a bug. Thank you!