6

By default, wagtail's StreamField looks something like this in the admin for empty fields, showing the different blocks available for the user: Default view of a StreamField in the wagtail admin

I would however prefer it to contain a block of my choosing by default. For example:

A StreamField control with a single rich text block with content

How would I accomplish this? Setting a default keyword argument for the field didn't seem to work.

cwj
  • 2,473
  • 5
  • 28
  • 38
  • Do you mean setting a default value on the RichTextBlock inside the StreamField? – cssidy May 01 '19 at 23:17
  • @cssidy while that is also useful, I was referring more to setting which block spawns by default, i.e. so it doesn't start out empty with the choices open – cwj May 02 '19 at 11:39
  • So what you're looking for is when a user clicks the plus icon on the StreamField, a RichTextBlock is pre-selected, skipping over the banner with other block types? Or, the banner with other block types stays open and a RichTextBlock appears below? – cssidy May 02 '19 at 14:01
  • My intention is that a user wouldn't have to click the "plus" icon and select a block at all. The field will come pre-populated with a block, and a user may add whatever other blocks they wish before/after or whatever – cwj May 15 '19 at 08:33
  • Can you post the code that you tried when you were setting the default? I believe the post needs a default value in the StreamField if you want its block to appear without someone opening the plus icon. – cssidy May 15 '19 at 15:15

1 Answers1

3

When you tried to set a default keyword, did you set it on the RichTextBlock inside the StreamField? According to the docs, all block types accept the following optional keyword arguments: default, label, group, icon, and template. For example:

body = StreamField([
        ('paragraph', blocks.RichTextBlock(default='Add you content here')),
    ])
cssidy
  • 395
  • 6
  • 16