Inserting internal anchor links into RichTextField?

1,011 views
Skip to first unread message

Lev Kanter

unread,
Oct 27, 2015, 4:21:09 PM10/27/15
to Wagtail support

I have a RichTextField where a CMS user needs to create internal links to specific sections on an internal page, so I'm looking to expand the "internal link" page chooser to accept an additional field to specify an anchor id.

I'm curious if anyone else has had to do this, or if there are other approaches to consider? Any suggestions/guidance here would be super helpful!

- Lev

Tom Talbot

unread,
Oct 28, 2015, 6:18:34 AM10/28/15
to Wagtail support
Hi Lev,

There's no functionality for doing this in rich text editors in Wagtail at the moment. You could either not use rich text and define the links as properties on the page, have the editors simply type out the links, or if you're willing to get your hands dirty you can build a custom Wagtail using Tim Heap's Unify link choosers pull request. You would then define a new link chooser that inherits from wagtail.wagtailadmin.link_choosers.LinkChooser, register it with @hooks.register('register_rich_text_link_chooser') and define some views and templates for the new chooser. Note that custom link choosers are not officially supported so if you go down that route you'll be heading into unknown territory.

Tom 

Joss Ingram

unread,
Oct 28, 2015, 7:24:27 AM10/28/15
to Wagtail support
We made our own button in the editor for adding targets and links for anchors. 

https://jossingram.wordpress.com/2014/07/24/add-some-blockquote-buttons-to-wagtail-cms-wysiwyg-editor/ this shows how to do a blockquote button but you use the same approach to make anchors


On Tuesday, 27 October 2015 20:21:09 UTC, Lev Kanter wrote:

Mevin Babu

unread,
Sep 16, 2016, 7:07:49 AM9/16/16
to Wagtail support
so is there any register_rich_text_link_chooser  that i can register my custom ones ? 

Matthew Westcott

unread,
Sep 16, 2016, 9:00:02 AM9/16/16
to wag...@googlegroups.com
Hi Mevin,

You can add toolbar buttons to Hallo.js using the insert_editor_js hook. You can see how the 'wagtaildocs' module does it here:

https://github.com/torchbox/wagtail/blob/2f8d00222dfe7f028c5a8375729db3b92b77dc27/wagtail/wagtaildocs/wagtail_hooks.py#L52

Cheers,
- Matt
Reply all
Reply to author
Forward
0 new messages