0

I have a page that is using both a RichTextField and a StreamField with RichTextBlocks.

class TwoColumnBlock(StructBlock):                                                                                     
    content = StructBlock(                                                                                             
        [
            ("left_column", StreamBlock([("paragraph", RichTextBlock()), ("image", ImageChooserBlock())], max_num=1)), 
            ("right_column", StreamBlock([("paragraph", RichTextBlock()), ("image", ImageChooserBlock())], max_num=1)),
        ]
    )
    
    
class ScrollingExhibitPage(Page):     
    banner_text = RichTextField(blank=True, features=["bold", "italic"])                                         
    body = StreamField(
        [("one_column", OneColumnBlock()), ("two_column", TwoColumnBlock())],            
        blank=True,                                                                                                    
    ) 

I'd like to have it so that anywhere a user is entering rich text, they are seeing the same options in the editor. However, I haven't been able to find any mention in the wagtail docs of how to set features for a RichTextBlock like you can for a RichTextField.

How would I go about doing that?

BrendaD
  • 15
  • 4

2 Answers2

0

You can use WAGTAILADMIN_RICH_TEXT_EDITORS to configure different feature sets you can use different places. So you could have a full-featured version for your default and then a minimal editor that only allows bold and italics in other places. So an example from my code:

WAGTAILADMIN_RICH_TEXT_EDITORS = {
    'default': {
        'WIDGET': 'wagtail.admin.rich_text.DraftailRichTextArea',
        # since sub, super, and a couple more are not included by default, we need to add them in this config
        'OPTIONS': {'features': ['bold', 'italic', 'superscript', 'subscript', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul',
                        'hr', 'blockquote', 'pre', 'link', 'embed', 'document-link', 'image']}
    },
    'minimal': {
        'OPTIONS': {
            'features': ['bold', 'italic', 'subscript', 'superscript', 'link']
        }
    }
}

And then when you want to use the minimal one, you can do something like:

description = RichTextField(
    editor='minimal',
    blank=True,
)

caption = blocks.RichTextBlock(
    required=False,
    label='Caption',
    editor='minimal',
)
cnk
  • 981
  • 1
  • 5
  • 9
0

RichTextBlock accepts a features argument just like RichTextField does - this is documented at https://docs.wagtail.org/en/stable/reference/streamfield/blocks.html#wagtail.blocks.RichTextBlock.

class TwoColumnBlock(StructBlock):                                                                                     
    content = StructBlock(                                                                                             
        [
            ("left_column", StreamBlock([("paragraph", RichTextBlock(features=["bold", "italic"])), ("image", ImageChooserBlock())], max_num=1)), 
            ("right_column", StreamBlock([("paragraph", RichTextBlock(features=["bold", "italic"])), ("image", ImageChooserBlock())], max_num=1)),
        ]
    )
gasman
  • 23,691
  • 1
  • 38
  • 56