Skip to content

Document how to disable diazo for ajax requests and completly. #1961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 6.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions docs/classic-ui/theming/diazo.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,68 @@ For instance, you may need to put together the main menu, the language change, a
Sometimes it is easier to override the corresponding template in Plone, build the new HTML structure there, and replace one thing in the {file}`rules.xml` file than trying to write complex Diazo rules or writing XSLT.

The size of the {file}`rules.xml` file and the number of rules it contains can negatively impact the performance of your site.


### Disable Diazo for AJAX requests

After sending an AJAX request from the client to Plone, Plone returns a JSON response.
Normally, this response should not get transformed by Diazo themes, and is usually handled in client-side JavaScript.

To prevent this transformation, disable AJAX requests for Diazo themes by using the `ajax_load` HTTP request parameter.
`ajax_load` is used in Plone to indicate AJAX requests.
When added to the query string, `ajax_load=1` disables a full page rendering, whereas `ajax_load=0` enables it.

````{versionadded} Plone 6.2
In Plone 6.2, the query parameter and its value `ajax_load=1` are automatically added to most AJAX requests by default.

```{seealso}
See the related pull request [Automatically set the ajax_load request parameter, `plone/Products.CMFPlone` #4169](https://github.com/plone/Products.CMFPlone/pull/4169).
```
````

Manually add the HTTP request parameter and its value as follows.

Add a theme parameter to your {file}`manifest.cfg` file.

```cfg
[theme:parameters]
ajax_load = python:request.get('ajax_load')
```

Then disable Diazo for AJAX requests in your {file}`rules.xml` file.

```xml
<notheme if="$ajax_load" /><!-- don't theme ajax requests -->
```

Choose any method to load this change in your theme.

- Restart your instance.
- In the {guilabel}`Theming` control panel, select another theme, then switch back to your own theme.
- For a programmatical way, see [(Re)Introduce the ajax_load theme parameter and skip diazo theming, if set. `plone/plonetheme.barceloneta` #404](https://github.com/plone/plonetheme.barceloneta/pull/404).


### Completely disable Diazo

You can fully disable Diazo for your theme.

Set the `X-Theme-Disabled` HTTP header before Diazo gets active, such as in an `IBeforeTraverseEvent` event subscriber, as shown in the following example.

Add an event subscriber in a {file}`subscribers.py` file in an add-on package.

```python
def disable_diazo(obj, event):
event.request.response.setHeader("X-Theme-Disabled", True)
```

Then register it in a {file}`configure.zcml` file.

```xml
<subscriber
for="*
zope.traversing.interfaces.IBeforeTraverseEvent"
handler=".subscribers.disable_diazo"
/>
```

Now Diazo should be disabled for all requests.