Skip to content

Commit

Permalink
Add caption to FormattedImageChooserStructBlock (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
brylie authored Oct 16, 2024
1 parent 3616826 commit 29c0c0e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion blocks/blocks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.core.validators import validate_slug
from django import forms
from django.core.validators import validate_slug
from django.forms.utils import flatatt
from django.utils.html import format_html, format_html_join
from wagtail import blocks as wagtail_blocks
Expand Down Expand Up @@ -44,6 +44,10 @@ class Meta:

class FormattedImageChooserStructBlock(wagtail_blocks.StructBlock):
image = ImageChooserBlock()
caption = wagtail_blocks.CharBlock(
required=False,
help_text="Optional caption (tooltip) to display with the image.",
)
width = wagtail_blocks.IntegerBlock(
min_value=0,
max_value=800,
Expand Down
4 changes: 4 additions & 0 deletions blocks/templates/blocks/blocks/formatted_image_block.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<img
src="{{ block_image.url }}"
width="{{ value.width }}"
{% if value.caption %}
title="{{ value.caption }}"
alt="{{ value.caption }}"
{% endif %}
{% if value.align == "right" %}
class="richtext-image right"
{% elif value.align == "left" %}
Expand Down

0 comments on commit 29c0c0e

Please sign in to comment.