Skip to content

Instantly share code, notes, and snippets.

@KalobTaulien
Created February 22, 2022 20:51
Show Gist options
  • Save KalobTaulien/bb0f331927f6c35c5dc9e3742a8021fd to your computer and use it in GitHub Desktop.
Save KalobTaulien/bb0f331927f6c35c5dc9e3742a8021fd to your computer and use it in GitHub Desktop.
Nested Wagtail StreamBlocks for nested sidebar content
from wagtail.core.models import Page
from wagtail.core import blocks
from wagtail.images.blocks import ImageChooserBlock
class NestedSidebarContent(blocks.StructBlock):
sidebar_alignment = blocks.ChoiceBlock(choices=(
("left", "Left"),
("right", "Right"),
))
main_content2 = blocks.StreamBlock([
("richtext", blocks.RichTextBlock()),
("image", ImageChooserBlock()),
])
sidebar_content2 = blocks.StreamBlock([
("richtext", blocks.RichTextBlock()),
("image", ImageChooserBlock()),
])
class SidebarBlock(blocks.StructBlock):
align = blocks.ChoiceBlock(choices=(
("left", "Left"),
("right", "Right"),
))
sidebar_content = blocks.StreamBlock([
("richtext", blocks.RichTextBlock()),
("image", ImageChooserBlock()),
])
full_width_content = blocks.StreamBlock([
("richtext", blocks.RichTextBlock()),
("image", ImageChooserBlock()),
("nested_sidebar", NestedSidebarContent())
])
class FullWidthBlock(blocks.StructBlock):
full_width_content = blocks.StreamBlock([
("richtext", blocks.RichTextBlock()),
("image", ImageChooserBlock()),
("nested_sidebar", NestedSidebarContent())
])
class HomePage(Page):
# ...
body = StreamField([
("sidebar_layout", SidebarBlock()),
("full_width_layout", FullWidthBlock()),
],
blank=True,
null=True,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment