Plone 6.1: plone_layout view: Add is_xhr and use_ajax methods. (5.x branch) #409
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theHTTP_X_REQUESTED_WITH
request header is set toXMLHttpRequest
. This is set by many JavaScript libraries. Barefetch
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, ifis_xhr
returns True,ajax_load
is unset or notFalse
and theplone.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 settingajax_load
, for Plone 6.2. Manually setting theajax_load
query parameter always takes precedence.Review Notes