{% interlace %} Tag
Include and render Interlace components in Django templates with automatic property passing and lifecycle management.
Basic usage
Load the template tags:
{% load interlace %}
Include a component:
{% interlace "ComponentName" %}
Passing properties
Pass data as keyword arguments:
{% interlace "UserCard"
title="Welcome"
count=42
is_active=True
username=user.username %}
- Literal values: strings, numbers, booleans
- Template variables:
user.username,post.title - Complex types: Django model instances, querysets
Django model instances
Pass full model objects directly:
{% interlace "UserProfile" person=request.user %}
In your component, type hint for autocomplete:
from django.contrib.auth.models import User
from interlace import Component
class UserProfile(Component):
person: User = None
def inline_template(self):
return """
<div>
<h2>{{ person.username }}</h2>
<p>{{ person.email }}</p>
</div>
"""
Components in loops
Use key for efficient rendering:
{% for post in posts %}
{% interlace "BlogPost" key=post.id post=post %}
{% endfor %}
Reserved Names Avoid
useras a component prop name - conflicts with Django'srequest.user. Useperson,profile, oraccountinstead.