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],
context_data: Mapping,
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(component_nodelist: NodeList, ComponentNodeCls: 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],
context_data: Mapping[str, Any],
fill_content: Dict[SlotName, FillContent],
) -> 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
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 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 | |