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

Update ImageGridBlock with LinkBlock #12585

Merged
merged 11 commits into from
Jul 17, 2024

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def generate_image_grid_field():
{
"image": choice(Image.objects.all()).id,
"caption": fake.paragraph(nb_sentences=1, variable_nb_sentences=False),
"link": [],
}
)

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from wagtail import blocks
from wagtail.images.blocks import ImageChooserBlock

from networkapi.wagtailpages.pagemodels.customblocks.link_block import (
LinkWithoutLabelBlock,
)


class ImageGridAltText(blocks.StructValue):
"""Get alt_text or default to image title."""
Expand All @@ -20,9 +24,8 @@ class ImageGrid(blocks.StructBlock):
required=False,
help_text="Please remember to properly attribute any images we use.",
)
url = blocks.CharBlock(
required=False,
help_text="Optional URL that this figure should link out to.",
link = blocks.ListBlock(
LinkWithoutLabelBlock(), min_num=0, max_num=1, help_text="Optional link that this figure should link out to."
)
square_image = blocks.BooleanBlock(
default=True,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
{% load wagtailcore_tags wagtailimages_tags %}

{% with url=value.url square=value.square_image %}
{% with square=value.square_image %}

<div class="tw-w-1/2 tw-px-8 {% if count > 3 %} small:tw-w-1/4 {% elif count == 3 %} small:tw-w-1/3 {% elif count == 2 %} small:tw-w-1/2 {% endif %} tw-mb-4 small:tw-mb-12">
{% if url %}<a href="{{ url }}">{% endif %}
{% if value.link %}
{% with link=value.link.0 %}
<a href="{{ link.url }}" {% if link.new_window %}target="_blank"{% endif %}>
{% endwith %}
{% endif %}
{% if square %}
{% image value.image fill-890x890-c100 format-jpeg class="tw-w-full" alt=value.alt %}
{% else %}
{% image value.image format-jpeg class="tw-w-full" alt=value.alt %}
{% endif %}
{% if url %}</a>{% endif %}
{% if value.link %}</a>{% endif %}

{% if value.caption %}
<p class="tw-my-4">
{% if url %}<a href="{{ url }}">{% endif %}
{{ value.caption }}
{% if url %}</a>{% endif %}
{% if value.link %}
{% with link=value.link.0 %}
<a href="{{ link.url }}" {% if link.new_window %}target="_blank"{% endif %}>{{ value.caption }}</a>
{% endwith %}
{% else %}
{{ value.caption }}
{% endif %}
</p>
{% endif %}
</div>
Expand Down
Loading