Skip to content
Advertisement

How to specify a template for a Snippet in a StreamField when using SnippetChooserBlock

I want to use a snippet in a StreamField:

JavaScript

my_page.html:

JavaScript

However, when rendering the Advert it renders only the str representation of self.text. How can I specify a template layout for the snippet block, e.g. like a StructBlock?

There is no documentation for SnippetChooserBlock.

Advertisement

Answer

Like all block types, SnippetChooserBlock accepts a template argument that specifies the path to a template to render for that block:

JavaScript

Within that template, the snippet instance is available as the variable value:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement