SpellBlocks
SpellBlocks are reusable content components that you can embed directly in your markdown. Think of them as Django template tags, but for markdown. They're perfect for creating rich, interactive content while keeping your markdown clean and readable.
Creating SpellBlocks
Every SpellBlock inherits from BasicSpellBlock
. Here's how to create one:
from django_spellbook.blocks import BasicSpellBlock, SpellBlockRegistry
@SpellBlockRegistry.register()
class MyBlock(BasicSpellBlock):
name = 'my_block' # This is what you'll use in markdown
template = 'my_app/blocks/my_block.html' # Your template path
def get_context(self):
context = super().get_context()
# Add your custom context here
return context
Built-in SpellBlocks
Alert Block
Creates attention-grabbing message boxes with different styles.
{~ alert type="warning" ~}
Hey! This is important stuff!
{~~}
Available Types:
- info (default)
- warning
- success
- danger
If you use an invalid type, it'll default to 'info' and print a warning message telling you what went wrong.
Card Block
Creates a card-style container for your content. Perfect for organizing related information.
{~ card title="Optional Title" footer="Optional Footer" class="any-extra-classes" ~}
Your card content here.
Supports **markdown** too!
{~~}
This is my Card
All parameters are optional. The card will still look good without them.
How SpellBlocks Work
- They process your markdown content first
- Apply any custom logic you define
- Render through a template
- Return the final HTML
The base BasicSpellBlock
handles:
- Markdown processing with common extensions
- Context management
- Template rendering
- Parameter validation
Read Next: Creating Custom SpellBlocks