Created
February 22, 2022 20:51
-
-
Save KalobTaulien/bb0f331927f6c35c5dc9e3742a8021fd to your computer and use it in GitHub Desktop.
Nested Wagtail StreamBlocks for nested sidebar content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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