wagtailwagtail-streamfield

How to set/define the value for the label in the minimap


Since Wagtail 4.1 a new minimap component is available in the editor interface.

For newly added blocks, the defined icon and the Meta class label of a subclassed StructBlock are shown.

However, after saving the page, the first field/block of the StructBlock is used as the label in the minimap.

How can I specify which field/block or text should be used as the label in the minimap?


Solution

  • The minimap uses the label_format attribute of the Meta class.

    
    class PanelBlock(StructBlock):
        headline = blocks.CharBlock(label=_('Headline'))
        text = blocks.RichTextBlock(label=_('Text'))
    
        class Meta:
            label = _('Infobox')
            icon = 'doc-empty'
            label_format = 'This is the label'  # <- This will be used as the label
    

    label_format – Determines the label shown when the block is collapsed in the editing interface. By default, the value of the first sub-block in the StructBlock is shown, but this can be customised by setting a string here with block names contained in braces - for example label_format = "Profile for {first_name} {surname}"

    Source: https://docs.wagtail.org/en/stable/reference/streamfield/blocks.html#wagtail.blocks.StructBlock