3

My company is using Wagtail to build robust pages for our website, likely using the StreamField component. We're wondering if Wagtail allows the possibility of us creating reusable parts (perhaps in a snippet), and injecting them into a page.

I'm including a simple diagram of what I'd like to do. Note that while snippets are one possible suggestion, it doesn't need to the specific solution.

enter image description here

The goal of course is to create an element which can be embedded in another page, but can be updated in a single place and cascade everywhere it's used.

Wordpress for example, has a plugin which offers this functionality in short code format:

[embed id=123456]
commadelimited
  • 5,656
  • 6
  • 41
  • 77

1 Answers1

2

You can create new block for stream field, let's say MySnippetBlock and then use SnippetChooserBlock to choose the snippet you want.

MySnippetBlock(StructBlock):
   title = CharBlock()
   snippet = SnippetChooserBlock()

Then in your StreamBlock field you can use above custom block:

MyPage(Page):
   stream_field_content = StreamField([('snippet_block', MySnippetBlock())])
...

Or you can use SnippetChooserBlock directly within StreamField if there is no need for additional info attached to it.

stream_field_content = StreamField([('snippet_block', SnippetChooserBlock())])
EastSw
  • 927
  • 1
  • 9
  • 28