下面是一种方法,感觉有点,如果有一种更自然的方法可以这样做,但希望能有所帮助。
有关Wagtail Hooks的说明,请参阅文档。
步骤1-隐藏内部链接选项
- 使用钩子
insert_editor_css
注入一些CSS以“隐藏”第一个链接。
- 这实现了与您尝试过的
_link_types
模板替代相同的目标,但仅将此作用域“限制”到了编辑器模式。
- 这很重要,因为您要避免破坏“移动页面”以及显示页面选择器的情况。 css有点笨拙,但希望能完成工作。
步骤2-将内部链接选项替换为模态的外部链接
代码
# file: wagtail_hooks.py
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.utils.html import format_html
from django.urls import reverse
from wagtail.core import hooks
@hooks.register('insert_editor_css')
def editor_css():
"""Add /static/css/admin.css to the admin."""
return format_html(
'<link rel="stylesheet" href="{}">',static("css/admin.css")
)
@hooks.register('insert_editor_js')
def editor_js():
return format_html(
"""
<script>
window.chooserUrls.pageChooser = '{}';
</script>
""",reverse('wagtailadmin_choose_page_external_link')
)
/* file: static/css/admin.css */
.modal-content .link-types :first-child {
/* hide the 'internal' link option from the page chooser */
display: none;
}
.modal-content .link-types {
/* ensure the 'before' element can be positioned absolute */
position: relative;
}
.modal-content .link-types::before {
/* hide the left '|' bar */
background: white;
bottom: 0;
content: '';
left: 0;
position: absolute;
top: 0;
width: 5px;
}
本文链接:https://www.f2er.com/3101248.html