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 block previews #521

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

laymonage
Copy link
Member

@laymonage laymonage commented Jan 23, 2025

Some blocks are intentionally left out, to test the behaviour of blocks that do not have previews enabled.

Different approaches are simulated:

  • Passing preview_value, description via init kwargs
  • Setting them in Meta
  • Overriding get_preview_value()
  • Custom preview_template to showcase using a static image for the preview

I didn't find a use case for overriding get_preview_context(), but let me know if we'd like to have it anyway.

Screen.Recording.2025-01-23.at.16.57.41.mov
Screen.Recording.2025-01-23.at.16.58.56.mov

Comment on lines +32 to +36
class CustomTypedTableBlock(TypedTableBlock):
def get_preview_value(self):
# Avoid having to construct TypedTable ourselves. This won't be
# necessary if https://github.com/wagtail/wagtail/pull/12808 is merged
return self.to_python(self.meta.preview_value)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +1 to +6
{% extends "wagtailcore/shared/block_preview.html" %}
{% load static %}

{% block content %}
<img class="static-block-preview" src="{% static "img/embed-block-preview.png" %}" alt="Preview of an embedded video" />
{% endblock %}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it'd be nice to showcase how a static image preview could work with the current implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

1 participant