Add <base> tag for preview panel in the default base.html template (#9132)

pull/9104/head
Sage Abdullah 2022-09-02 16:44:02 +01:00 zatwierdzone przez Matt Westcott
rodzic 40c9d07b24
commit 54597bb65d
4 zmienionych plików z 21 dodań i 0 usunięć

Wyświetl plik

@ -21,6 +21,7 @@ Changelog
* Fix: On the Locked Pages report, limit the "locked by" filter to just users who have locked pages (Stefan Hammer)
* Fix: Prevent JavaScript error when using StreamField on views without commenting support, such as snippets (Jacob Topp-Mugglestone)
* Fix: Modify base template for new projects so that links opened from the preview panel open in a new window (Sage Abdullah)
4.0 (31.08.2022)

Wyświetl plik

@ -15,3 +15,4 @@ depth: 1
* On the Locked Pages report, limit the "locked by" filter to just users who have locked pages (Stefan Hammer)
* Prevent JavaScript error when using StreamField on views without commenting support, such as snippets (Jacob Topp-Mugglestone)
* Modify base template for new projects so that links opened from the preview panel open in a new window (Sage Abdullah)

Wyświetl plik

@ -271,6 +271,20 @@ There are also many improvements to the documentation both under the hood and in
As part of making previews available to non-page models, the `serve_preview()` method has been decoupled from the `serve()` method and extracted into the `PreviewableMixin` class. If you have overridden the `serve()` method in your page models, you will likely need to override `serve_preview()`, `get_preview_template()`, and/or `get_preview_context()` methods to handle previews accordingly. Alternatively, you can also override the `preview_modes` property to return an empty list to disable previews.
### Opening links within the live preview panel
The live preview panel utilises an iframe to display the preview in the editor page, which requires the page in the iframe to have the `X-Frame-Options` header set to `SAMEORIGIN` (or unset). If you click a link within the preview panel, you may notice that the iframe stops working. This is because the link is loaded within the iframe and the linked page may have the `X-Frame-Options` header set to `DENY`. To work around this problem, add the following `<base>` tag within your `<head>` element in your `base.html` template, before any `<link>` elements:
```html+django
{% if request.in_preview_panel %}
<base target="_blank">
{% endif %}
```
This will make all links in the live preview panel open in a new tab.
As of Wagtail 4.0.1, new Wagtail projects created through the `wagtail start` command already include this change in the base template.
### `base_url_path` keyword argument added to AdminURLHelper
The `wagtail.contrib.modeladmin.helpers.AdminURLHelper` class now accepts a `base_url_path` keyword argument on its constructor. Custom subclasses of this class should be updated to accept this keyword argument.

Wyświetl plik

@ -16,6 +16,11 @@
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
{% templatetag opencomment %} Force all links in the live preview panel to be opened in a new tab {% templatetag closecomment %}
{% templatetag openblock %} if request.in_preview_panel {% templatetag closeblock %}
<base target="_blank">
{% templatetag openblock %} endif {% templatetag closeblock %}
{% templatetag opencomment %} Global stylesheets {% templatetag closecomment %}
<link rel="stylesheet" type="text/css" href="{% templatetag openblock %} static 'css/{{ project_name }}.css' {% templatetag closeblock %}">