Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add caption to FormattedImageChooserStructBlock #1130

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading