bolt / core

🧿 Bolt 5 core
https://boltcms.io
MIT License
533 stars 159 forks source link

pager() throws an error when used on homepage #2845

Open dbeerten opened 2 years ago

dbeerten commented 2 years ago

When using the pager function, together with setcontent on the homepage (root url /) this error is thrown:

image

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

bobdenotter commented 2 years ago

I think it does work, if you tell it what to use for paging. In your case {{ pager(records) }}.

dbeerten commented 2 years ago

Thanks for the quick feedback @bobdenotter

Unfortunately, this results in the same error: image

bobdenotter commented 2 years ago

It works for me, strange:

image image

Can you close Exception "1" (the 'minus' on the right) and see what Exception "2" says?

dbeerten commented 2 years ago

image

Marmelatze commented 2 years ago

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

I-Valchev commented 2 years ago

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 :-)

Marmelatze commented 2 years ago

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.

Igor-san commented 2 years ago

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()
        );
nestordedios commented 2 years ago

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?

dbeerten commented 2 years ago

@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 to homepage: homepage and changing the template fixed it for me

abdellahrk commented 2 years ago

Since there's a fix won't it be cool if this issue is closed? @dbeerten

drojaazu commented 1 year ago

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!