slots ¤
FillContent dataclass
¤
FillContent(content_func: SlotFunc[TSlotData], slot_default_var: Optional[SlotDefaultName], slot_data_var: Optional[SlotDataName])
Bases: Generic[TSlotData]
This represents content set with the {% fill %}
tag, e.g.:
{% component "my_comp" %}
{% fill "first_slot" %} <--- This
hi
{{ my_var }}
hello
{% endfill %}
{% endcomponent %}
FillNode ¤
FillNode(nodelist: NodeList, kwargs: RuntimeKwargs, trace_id: str, node_id: Optional[str] = None, is_implicit: bool = False)
Bases: BaseNode
Set when a component
tag pair is passed template content that excludes fill
tags. Nodes of this type contribute their nodelists to slots marked as 'default'.
Source code in src/django_components/slots.py
Slot ¤
SlotFill dataclass
¤
SlotFill(
name: str,
escaped_name: str,
is_filled: bool,
content_func: SlotFunc[TSlotData],
slot_default_var: Optional[SlotDefaultName],
slot_data_var: Optional[SlotDataName],
)
Bases: Generic[TSlotData]
SlotFill describes what WILL be rendered.
It is a Slot that has been resolved against FillContents passed to a Component.
SlotNode ¤
SlotNode(
nodelist: NodeList,
trace_id: str,
node_id: Optional[str] = None,
kwargs: Optional[RuntimeKwargs] = None,
is_required: bool = False,
is_default: bool = False,
)
Bases: BaseNode
Source code in src/django_components/slots.py
SlotRef ¤
SlotRef allows to treat a slot as a variable. The slot is rendered only once the instance is coerced to string.
This is used to access slots as variables inside the templates. When a SlotRef is rendered in the template with {{ my_lazy_slot }}
, it will output the contents of the slot.
Source code in src/django_components/slots.py
parse_slot_fill_nodes_from_component_nodelist ¤
parse_slot_fill_nodes_from_component_nodelist(nodes: Tuple[Node, ...], ignored_nodes: Tuple[Type[Node]]) -> List[FillNode]
Given a component body (django.template.NodeList
), find all slot fills, whether defined explicitly with {% fill %}
or implicitly.
So if we have a component body:
{% component "mycomponent" %}
{% fill "first_fill" %}
Hello!
{% endfill %}
{% fill "second_fill" %}
Hello too!
{% endfill %}
{% endcomponent %}
django.template.Node
) for fill "first_fill"
and fill "second_fill"
. Source code in src/django_components/slots.py
resolve_slots ¤
resolve_slots(
context: Context,
template: Template,
component_name: Optional[str],
fill_content: Dict[SlotName, FillContent],
is_dynamic_component: bool = False,
) -> Tuple[Dict[SlotId, Slot], Dict[SlotId, SlotFill]]
Search the template for all SlotNodes, and associate the slots with the given fills.
Returns tuple of: - Slots defined in the component's Template with {% slot %}
tag - SlotFills (AKA slots matched with fills) describing what will be rendered for each slot.
Source code in src/django_components/slots.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 |
|