lace:init

Call methods or set properties when a component initializes.

PREVIEW
Status: waiting…
class InitDemo(Component):
    status: str = "waiting…"

    def ready(self):
        self.status = "ready ✓ - ran on init"

    def inline_template(self):
        return """
        <div lace:init="ready" class="...">
            Status: <strong>{{ status }}</strong>
        </div>
        """

Syntax

<div lace:init="method_name"></div>
<div lace:init="property = value"></div>

Behavior

Executes after component mounts on initial page load. Useful for triggering side effects or setting initial state based on client-side data.

Examples

Call Method on Init

class Dashboard(Component):
    data: dict = {}

    def load_user_preferences(self):
        # Load preferences from localStorage via Alpine
        self.data = {"theme": "dark", "language": "en"}
<div lace:init="load_user_preferences">
    Theme: {{ data.theme }}
</div>

Set Property on Init

<div lace:init="initialized = true">
    {% if initialized %}
        <p>Component is ready</p>
    {% endif %}
</div>

Multiple Init Directives

<div lace:init="fetch_data">
    <span lace:init="log_view">Content</span>
</div>

View this page as markdown - handy as context for your AI tools. Full index at /llms.txt.

Theme
Accent
Ink