Skip to content

Latest commit

 

History

History
68 lines (49 loc) · 1.59 KB

expander.md

File metadata and controls

68 lines (49 loc) · 1.59 KB

Expander

from wagtail.core.models import Page
from wagtail.core.fields import StreamField

from wagtailnhsukfrontend.blocks import ExpanderBlock,

class MyPage(Page):
  body = StreamField([
      ...
      ('expander', ExpanderBlock()),
      ...
  ], use_json_field=True)

By default, the expander block can contain the following sub-blocks:

To add extra sub-blocks, you must extend the ExpanderBlock class.

class CustomExpanderBody(ExpanderBlock.BodyStreamBlock):

  # Add a custom block
  extra = MyExtraBlock()


class CustomExpanderBlock(ExpanderBlock):

  body = CustomExpanderBody(required=True)


class MyPage(Page):
  body = StreamField([
      ...
      ('expander', CustomExpanderBlock()),
      ...
  ], use_json_field=True)

Expander Group

An expander group should be used when multiple expanders are required in a list.

from wagtail.core.models import Page
from wagtail.core.fields import StreamField

from wagtailnhsukfrontend.blocks import ExpanderGroupBlock,

class MyPage(Page):
  body = StreamField([
      ...
      ('group_expander', ExpanderGroupBlock()),
      ...
  ], use_json_field=True)

Reference