Skip to content

Conversation

thet
Copy link
Member

@thet thet commented Jul 31, 2025

Add two new methods to the Plone layout view:

  • is_xhr: Returns True, if an AJAX request is detected. This is done by checking if the HTTP_X_REQUESTED_WITH request header is set to XMLHttpRequest. This is set by many JavaScript libraries. Bare fetch requests do not set this without any other intercention, though. So, is_xhr is not guaranteed to really detect every and all XHR requests.

  • use_ajax: Returns True, if is_xhr returns True, ajax_load is unset or not False and the plone.use_ajax registry parameter is set to True. This can be used to automatically switch to the ajax main template for XHR requests instead of manually setting ajax_load, for Plone 6.2. Manually setting the ajax_load query parameter always takes precedence.

Review Notes

@mister-roboto
Copy link

@thet thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

Add two new methods to the Plone layout view:

- `is_xhr`: Returns True, if an AJAX request is detected. This is done by
  checking if the `HTTP_X_REQUESTED_WITH` request header is set to
  `XMLHttpRequest`. This is set by many JavaScript libraries. Bare `fetch`
  requests do not set this without any other intercention, though. So, `is_xhr`
  is not guaranteed to really detect every and all XHR requests.

- `use_ajax`: Returns True, if `is_xhr` returns True, `ajax_load` is unset or
  not `False` and the `plone.use_ajax` registry parameter is set to True. This
  can be used to automatically switch to the ajax main template for XHR requests
  instead of manually setting `ajax_load`, for Plone 6.2.
  Manually setting the `ajax_load` query parameter always takes precedence.
@thet
Copy link
Member Author

thet commented Jul 31, 2025

@jenkins-plone-org please run jobs

@thet thet changed the title plone_layout view: Add is_xhr and use_ajax methods. (5.x branch) Plone 6.1: plone_layout view: Add is_xhr and use_ajax methods. (5.x branch) Jul 31, 2025
@thet thet requested review from mauritsvanrees and petschki July 31, 2025 21:35
@thet
Copy link
Member Author

thet commented Sep 22, 2025

This feature doesn't go into Plone 6.1 but in 6.2.
See: plone/Products.CMFPlone#4188

6.2 implementation: #405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants