Pdopage ajax pagination not working on multilanguage website


I am having an issue with pdopage ajax pagination on a multilanguage website.
The main language is ok, it loads the other pages without problem, but with the second language it stop on the first page.

You can find an example here:

the italian version is OK, but when I switch to English, is not working anymore:

I have no error in the js console, but looking in the network panel, there is this request

Can be related to the problem? In the Italian side, there is only connector.php followed by the images.

This is the code I use for the pdopage call:

      <div class="col" id="pdopage">
        <div class="rows row row-cols-lg-3 row-cols-md-2 row-cols-1 gy-4 item-list">

Thank you for any help.

To load the data for the second page, the connector assets/components/pdotools/connector.php gets executed.

The connector should return JSON, but for your “it” context, it returns HTML (probably the content of the “error” page).

Theoretically, the connector checks if the requested page (request parameter “pageId”) is in a different context and switches to that context here in the code:

Maybe when the code invokes the event “OnHandleRequest” on this line

your router plugin switches the context again.

To debug the problem, can you test if it works correctly when you (temporarilly) comment out line 26 that invokes the “OnHandleRequest” event?

What extra do you use to switch the contexts? Or did you write a custom plugin?

thanks @halftrainedharry ,

well, if I comment the line 26, it works!
I use languagerouter to switch contexts with these context settings:

for the Italian context

for the english context

any suggestion?

Do you mean the extra LangRouter?

There already exist similar issues in the Github repos of both pdoTools and LangRouter:

I believe the issue has to be fixed in the code.
Maybe LangRouter could use the event OnMODXInit instead, so that invoking the event OnHandleRequest doesn’t switch the context.
Or pdoTools could introduce an option to disable the invoking of OnHandleRequest.

LangRouter does not just switch the context, it initializes the context and the culture. Maybe that’s missing in the pdoPage connector.

Ok, so I tested it.

To load the items for the second page via AJAX, pdoTools calls the file assets/components/pdotools/connector.php.
In this connector $modx->invokeEvent('OnHandleRequest'); is executed.
This runs the LangRouter plugin.
There is no request parameter “q” (because it’s a request to a connector), so the code switches the context here (depending on the request header “HTTP_ACCEPT_LANGUAGE”)

and then makes a redirect here

Then the q parameter has to be set in the pdoPage connector.

This is one possible solution for this specific problem.
But it could theoretically generate different issues with other router plugins.

Alternative you could check $_SERVER['REQUEST_URI'] in the LangRouter plugin, and stop processing it, if for example the request is for a “connector.php” file.

Handling the q parameter is quite essential in other routing plugins: https://github.com/SEDAdigital/XRouting/blob/bedc4d212151500d90075a63d7b5f7a7b2effcac/core/components/xrouting/elements/plugins/xrouting.plugin.php#L147

Sure, but for this request (to the pdoTools-connector), the routing-plugins shouldn’t do anything at all. MODX was already switched to the correct context.

$modx->invokeEvent('OnHandleRequest'); is only called as a workaround to make ClientConfig placeholders available.

If a routing-plugin has no “q” request parameter and just keeps the current context, then everything works ok.
The “problem” with LangRouter is, that if there is no “q” request parameter, the code guesses the most likely context (depending on the request header “HTTP_ACCEPT_LANGUAGE”) and therefore “wrongly” switches the context (in some cases).

The q request parameter is essential for displaying the MODX frontend. The pdoPage snippet wants to render a part of the frontend and the pdoPage connector has to set that essential parameter or it has to tell MODX (and other parts), that it runs in connector mode.

Aassuming that pdoPage developer should handle this p parameter, it is safe to leave the OnHandleRequest commented?

I have already checked the website and seems working fine, as usual.

The problem with changing the file assets/components/pdotools/connector.php directly is, that on the next update (of the extra), all your changes will get overwritten.
So if the developer of pdoTools doesn’t fix the issue, your site will break again.

So maybe instead, you could try something like this:

  • Copy the connector assets/components/pdotools/connector.php to a custom folder. (e.g. assets/components/mypackage/)
  • In this copied connector, delete the line that invokes the event OnHandleRequest.
  • Copy the file assets/components/pdotools/js/pdopage.js to a custom folder. (e.g. assets/components/mypackage/js/)
  • In the copied JS file, change this line

to $.post('/assets/components/mypackage/connector.php', params, function (response) { so that your custom connector gets called.

  • Change the pdoPage tag in the resource to use the custom JS file.

Thank you @halftrainedharry it works!

If the developer of pdoTools fix the issue, i will change back to the original connector.


This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.