Wagtail Unboxed episode 08 4:37
Snippets and reusable content
Content that isn't a page: a team member, a testimonial. No URL, no place in the tree, but they belong on several pages. That is a snippet. Plus tags for the journal.
What this episode covers
And the bug that tag filtering introduces: click "Older" on a filtered list and page 2 quietly shows every post, because the pagination link forgot the tag.
What you'll learn
- What a snippet is, and when content should be one instead of a page
TeamMemberwith Orderable — drag-and-drop ordering for freeSnippetViewSetandSnippetViewSetGroup: the Wagtail 7 way to register snippets- Two ways to use a snippet: chosen per page, or fetched by the block
get_contexton a block- The circular import between
blocks.pyandmodels.py, and the two ways around it - What happens when you delete a snippet a page is using
- Tags with
ClusterTaggableManager, and why the through model needs aParentalKey - Filtering by tag, and keeping the filter through pagination
Chapters
- 0:00 Content that isn't a page
- 0:23 Two snippet models
- 0:39 SnippetViewSet
- 1:01 Two ways to use a snippet
- 1:24 get_context on a block
- 1:36 The circular import
- 1:57 Deleting a snippet a page uses
- 2:29 Tags, and why ParentalKey
- 2:49 Filtering by tag
- 3:00 Pagination forgets the filter
- 3:17 Carry every parameter
- 3:36 Fixed on the way
- 3:51 The team
- 3:59 A testimonial
- 4:06 The journal, filtered
- 4:13 Commit and tag
- 4:17 Next episode
Versions on screen
Wagtail 7.4.3 · Django 6.1.1 · Python 3.12. Recorded on Windows; macOS and Linux commands are in the repository for every episode.