Content Loader

Style-agnostic content loader / suspense component.

python 8 params

Preview

loaded

Loading…

python
content_loader(loaded=False, placeholder='<p>Loading…</p>')

Usage

views.py
python
from djust import LiveView
from djust.components import ContentLoader
from django.utils.safestring import mark_safe


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = ContentLoader(loaded=False, placeholder=mark_safe('<p>Loading…</p>'))
my_template.html
django
{{ component }}

Parameters

NameTypeDefaultDescription
loading_eventstr — the event your server pushes to it'data_loaded'Server event name that signals content is ready
loadedboolFalseWhether content has loaded (default: False)
placeholderstr''HTML string to show while loading (e.g. skeleton)
contentstr''Actual content to show when loaded
errorstr''Error message to display if loading failed
error_eventstr — renames the event; identity is `name`''Optional event name for retry action
custom_classstr''Additional CSS classes
**kwargs— passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state——
Source & styles
FilePathNotes
moduledjust.components.components.content_loaderSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 2 of this component's classes at line 1794, 1795. Override those rules, or the custom properties they read, in a stylesheet loaded after it.