curt
curt

Reputation: 4592

Wagtail Stream Image Ignoring HTML File

I've set up a stream file and all the blocks work except image. I know I must have overlooked something obvious. The image is displayed. It just ignores the html. In my models.py, I have:

    content = StreamField(
    [
        ("title_and_text", blocks.TitleTextBlock()),
        ("full_rich_text", blocks.RichTextBlock()),
        ("simple_rich_text", blocks.LimitedRichTextBlock()),
        ("image_float_left", blocks.ImageChooserBlock()),
    ],
    null=True,
    blank=True,
 )

In my page html, I have:

{% for block in page.content %}
    {% include_block block %}
{% endfor %}

All the other blocks display correctly. In my blocks.py, I have:

class ImageFloatLeftBlock(ImageChooserBlock):
"""Float an image to the left"""

class Meta:
    template = "streams/image_float_left_block.html"
    icon = "doc-full"
    label = "Float Image Left"

The html file is ignored. I put and h1 in it just to be sure. The image is being displayed. I assume it isn't looking at the streams/image_float_left_block.html file. It does work for the other fields that are set up the same way. For example, this one works:

class TitleTextBlock(blocks.StructBlock):
"""Title and text and nothing else."""

title = blocks.CharBlock(required=True, help_text="The heading for the block")
text = blocks.TextBlock(required=True, help_text="The body of the block")

class Meta:
    template = "streams/title_text_block.html"
    icon = "edit"
    label = "Title & Text"

I suspect it's the parent class in the invocation:

class ImageFloatLeftBlock(ImageChooserBlock):

I can't find anything more appropriate in the blocks import. What would be the appropriate parent class or is there some other problem?

Upvotes: 1

Views: 146

Answers (1)

gasman
gasman

Reputation: 25292

In the StreamField definition, you haven't told it to use your custom ImageFloatLeftBlock subclass, so it's still using the basic ImageChooserBlock which doesn't have your template setting. It should be:

content = StreamField(
    [
        ("title_and_text", blocks.TitleTextBlock()),
        ("full_rich_text", blocks.RichTextBlock()),
        ("simple_rich_text", blocks.LimitedRichTextBlock()),
        ("image_float_left", blocks.ImageFloatLeftBlock()),
    ],
    null=True,
    blank=True,
 )

Upvotes: 2

Related Questions