Repository: wagtail/wagtail
File: wagtail/blocks/base.py (Python)

Code before:
            warnings.warn(
                f"{self.__class__.__name__}.get_template should accept a 'value' argument as first argument",
                RemovedInWagtail70Warning,
            )

        template = self.get_template(**args)
        if not template:
            return self.render_basic(value, context=context)

        if context is None:
            new_context = self.get_context(value)
        else:
            new_context = self.get_context(value, parent_context=dict(context))

        return mark_safe(render_to_string(template, new_context))

    def get_preview_context(self, value, parent_context=None):
        # We do not fall back to `get_context` here, because the preview context
        # will be used for a complete view, not just the block. Instead, the
        # default preview context uses `{% include_block %}`, which will use
        # `get_context`.
        return parent_context or {}

    def get_preview_template(self, value, context=None):
        # We do not fall back to `get_template` here, because the template will
        # be used for a complete view, not just the block. In most cases, the
        # block's template cannot stand alone for the preview, as it would be
        # missing the necessary static assets.
        #
        # Instead, the default preview template uses `{% include_block %}`,
        # which will use `get_template` if a template is defined.
        return (
            getattr(self.meta, "preview_template", None)
            or self.DEFAULT_PREVIEW_TEMPLATE
        )

    def get_preview_value(self):
        if hasattr(self.meta, "preview_value"):
            return self.normalize(self.meta.preview_value)
        return self.get_default()

    @cached_property
    def _has_default(self):
        return getattr(self.meta, "default", None) is not None

    @cached_property
    def is_previewable(self):
        # To prevent showing a broken preview if the block preview has not been
        # configured, consider the block to be previewable if either:
        # - a specific preview template is configured for the block
        # - a preview value is provided and the global template has been overridden

Review comment (suggestion):
The `page_title` variable is intentionally undocumented as it's not that relevant for configuring the preview, and may be confused for `Page.title`.

Code after:
                f"{self.__class__.__name__}.get_template should accept a 'value' argument as first argument",
                RemovedInWagtail70Warning,
            )

        template = self.get_template(**args)
        if not template:
            return self.render_basic(value, context=context)

        if context is None:
            new_context = self.get_context(value)
        else:
            new_context = self.get_context(value, parent_context=dict(context))

        return mark_safe(render_to_string(template, new_context))

    def get_preview_context(self, value, parent_context=None):
        """
        Return a dict of context variables to be used as the template context
        when rendering the block's preview. The ``value`` argument is the value
        returned by :meth:`get_preview_value`. The ``parent_context`` argument
        contains the following variables:

        - ``request``: The current request object.
        - ``block_def``: The block instance.
        - ``block_class``: The block class.
        - ``bound_block``: A ``BoundBlock`` instance representing the block and its value.

        If :ref:`the global preview template <streamfield_global_preview_template>`
        is used, the block will be rendered as the main content using
        ``{% include_block %}``, which in turn uses :meth:`get_context`. As a
        result, the context returned by this method will be available as the
        ``parent_context`` for ``get_context()`` when the preview is rendered.
        """
        # NOTE: see StreamFieldBlockPreview.base_context for the context variables
        # that can be documented.
        return parent_context or {}

    def get_preview_template(self, value, context=None):
        """
        Return the template to use for rendering the block's preview. The ``value``
        argument is the value returned by :meth:`get_preview_value`. The ``context``
        argument contains the variables listed for the ``parent_context`` argument
        of :meth:`get_preview_context` above (and not the context returned by that
        method itself).

        Note that the preview template is used to render a complete HTML page of
        the preview, not just an HTML fragment for the block. The method returns
        the ``preview_template`` attribute from the block's options if provided,
        and falls back to
        :ref:`the global preview template <streamfield_global_preview_template>`
        otherwise.