.html``. For example:
- ``Button`` → ``bricks/button.html``
- ``AlertBox`` → ``bricks/alert_box.html``
You can customize the template path:
.. code-block:: python
@register
class Button(Brick):
label: str
template_name = "components/ui/button.html"
Required vs Optional Kwargs
---------------------------
Kwargs without default values are required:
.. code-block:: python
@register
class Button(Brick):
label: str # Required - must be provided
variant: str = "primary" # Optional - defaults to "primary"
size: str | None = None # Optional - defaults to None
Using required kwargs without providing them raises an error:
.. code-block:: html+django
{# This will raise BrickValidationError #}
{% button variant="secondary" %}
{# This works #}
{% button label="Click me" variant="secondary" %}
Block Bricks
------------
Block bricks can wrap content. Use ``BlockBrick`` as your base class:
.. code-block:: python
from brickastley import BlockBrick, register
@register
class Card(BlockBrick):
title: str
subtitle: str | None = None
Create the template with a ``{{ children }}`` variable:
.. code-block:: html+django
{# bricks/card.html #}
Use it with an end tag:
.. code-block:: html+django
{% card title="Welcome" subtitle="Getting started" %}
This is the card content.
You can include any HTML here.
{% button label="Learn more" %}
{% endcard %}
Next Steps
----------
- Learn about :doc:`advanced features ` like Media classes and custom context
- Check out the :doc:`API reference ` for complete documentation