admin管理员组文章数量:1393880
When someone adds an external link in Wagtail CMS, they should have the option to choose whether to make the link 'nofollow' or 'noreferrer.' To achieve this, I have inherited the existing link form, and the code is provided here
class CustomExternalLinkChooserForm(ExternalLinkChooserForm):
rel = forms.ChoiceField(
choices=[
("noreferrer", "Noreferrer"),
("nofollow", "Nofollow"),
],
required=False,
label=_("Rel Attribute"),
)
i have also inherited view
class CustomExternalLinkView(ExternalLinkView):
form_class = CustomExternalLinkChooserForm
i registered this in wagtail hooks so admin take this override core view
@hooks.register("register_admin_urls")
def register_custom_external_link_view():
return [
path(
"admin/choose-external-link/",
CustomExternalLinkView.as_view(),
name="wagtailadmin_choose_page_external_link",
)
]
By using the above, it gives me an output like this, but the main issue is that when the Draftail rich text editor saves the link in the database, it does not add the rel attribute in href url. How can I solve this issue?
When someone adds an external link in Wagtail CMS, they should have the option to choose whether to make the link 'nofollow' or 'noreferrer.' To achieve this, I have inherited the existing link form, and the code is provided here
class CustomExternalLinkChooserForm(ExternalLinkChooserForm):
rel = forms.ChoiceField(
choices=[
("noreferrer", "Noreferrer"),
("nofollow", "Nofollow"),
],
required=False,
label=_("Rel Attribute"),
)
i have also inherited view
class CustomExternalLinkView(ExternalLinkView):
form_class = CustomExternalLinkChooserForm
i registered this in wagtail hooks so admin take this override core view
@hooks.register("register_admin_urls")
def register_custom_external_link_view():
return [
path(
"admin/choose-external-link/",
CustomExternalLinkView.as_view(),
name="wagtailadmin_choose_page_external_link",
)
]
By using the above, it gives me an output like this, but the main issue is that when the Draftail rich text editor saves the link in the database, it does not add the rel attribute in href url. How can I solve this issue?
Share Improve this question asked Mar 27 at 14:07 Dhruvin KalathiyaDhruvin Kalathiya 113 bronze badges1 Answer
Reset to default 0You will also need to customize the LinkHandlers. There is an example in the docs for how to add nofollow to all links. You will need to modify it to accept your dynamic attribute. https://docs.wagtail./en/stable/extending/rich_text_internals.html#registering-rewrite-handlers
版权声明:本文标题:django - How can i edit external link format converter rule in wagtail cms draftail editor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744082620a2587928.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论