Search code examples
wagtailrichtextwagtail-streamfield

How to specify features for a RichTextBlock in wagtail


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?


Solution

  • 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)),
            ]
        )