django-components 0.95__tar.gz → 0.97__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. {django_components-0.95/src/django_components.egg-info → django_components-0.97}/PKG-INFO +321 -60
  2. {django_components-0.95 → django_components-0.97}/README.md +320 -59
  3. {django_components-0.95 → django_components-0.97}/pyproject.toml +1 -1
  4. {django_components-0.95 → django_components-0.97}/src/django_components/__init__.py +5 -0
  5. {django_components-0.95 → django_components-0.97}/src/django_components/component.py +280 -44
  6. {django_components-0.95 → django_components-0.97}/src/django_components/slots.py +21 -13
  7. django_components-0.97/src/django_components/template.py +42 -0
  8. {django_components-0.95 → django_components-0.97}/src/django_components/templatetags/component_tags.py +1 -1
  9. {django_components-0.95 → django_components-0.97}/src/django_components/types.py +14 -1
  10. django_components-0.97/src/django_components/utils.py +213 -0
  11. {django_components-0.95 → django_components-0.97/src/django_components.egg-info}/PKG-INFO +321 -60
  12. {django_components-0.95 → django_components-0.97}/src/django_components.egg-info/SOURCES.txt +2 -0
  13. {django_components-0.95 → django_components-0.97}/tests/test_component.py +607 -40
  14. {django_components-0.95 → django_components-0.97}/tests/test_context.py +50 -17
  15. django_components-0.97/tests/test_template.py +67 -0
  16. {django_components-0.95 → django_components-0.97}/tests/test_templatetags_slot_fill.py +1 -1
  17. {django_components-0.95 → django_components-0.97}/tests/testutils.py +4 -0
  18. django_components-0.95/src/django_components/utils.py +0 -38
  19. {django_components-0.95 → django_components-0.97}/LICENSE +0 -0
  20. {django_components-0.95 → django_components-0.97}/setup.cfg +0 -0
  21. {django_components-0.95 → django_components-0.97}/src/django_components/app_settings.py +0 -0
  22. {django_components-0.95 → django_components-0.97}/src/django_components/apps.py +0 -0
  23. {django_components-0.95 → django_components-0.97}/src/django_components/attributes.py +0 -0
  24. {django_components-0.95 → django_components-0.97}/src/django_components/autodiscover.py +0 -0
  25. {django_components-0.95 → django_components-0.97}/src/django_components/component_media.py +0 -0
  26. {django_components-0.95 → django_components-0.97}/src/django_components/component_registry.py +0 -0
  27. {django_components-0.95 → django_components-0.97}/src/django_components/components/__init__.py +0 -0
  28. {django_components-0.95 → django_components-0.97}/src/django_components/components/dynamic.py +0 -0
  29. {django_components-0.95 → django_components-0.97}/src/django_components/context.py +0 -0
  30. {django_components-0.95 → django_components-0.97}/src/django_components/expression.py +0 -0
  31. {django_components-0.95 → django_components-0.97}/src/django_components/library.py +0 -0
  32. {django_components-0.95 → django_components-0.97}/src/django_components/logger.py +0 -0
  33. {django_components-0.95 → django_components-0.97}/src/django_components/management/__init__.py +0 -0
  34. {django_components-0.95 → django_components-0.97}/src/django_components/management/commands/__init__.py +0 -0
  35. {django_components-0.95 → django_components-0.97}/src/django_components/management/commands/startcomponent.py +0 -0
  36. {django_components-0.95 → django_components-0.97}/src/django_components/management/commands/upgradecomponent.py +0 -0
  37. {django_components-0.95 → django_components-0.97}/src/django_components/middleware.py +0 -0
  38. {django_components-0.95 → django_components-0.97}/src/django_components/node.py +0 -0
  39. {django_components-0.95 → django_components-0.97}/src/django_components/provide.py +0 -0
  40. {django_components-0.95 → django_components-0.97}/src/django_components/py.typed +0 -0
  41. {django_components-0.95 → django_components-0.97}/src/django_components/safer_staticfiles/__init__.py +0 -0
  42. {django_components-0.95 → django_components-0.97}/src/django_components/safer_staticfiles/apps.py +0 -0
  43. {django_components-0.95 → django_components-0.97}/src/django_components/tag_formatter.py +0 -0
  44. {django_components-0.95 → django_components-0.97}/src/django_components/template_loader.py +0 -0
  45. {django_components-0.95 → django_components-0.97}/src/django_components/template_parser.py +0 -0
  46. {django_components-0.95 → django_components-0.97}/src/django_components/templatetags/__init__.py +0 -0
  47. {django_components-0.95 → django_components-0.97}/src/django_components.egg-info/dependency_links.txt +0 -0
  48. {django_components-0.95 → django_components-0.97}/src/django_components.egg-info/requires.txt +0 -0
  49. {django_components-0.95 → django_components-0.97}/src/django_components.egg-info/top_level.txt +0 -0
  50. {django_components-0.95 → django_components-0.97}/tests/test_attributes.py +0 -0
  51. {django_components-0.95 → django_components-0.97}/tests/test_autodiscover.py +0 -0
  52. {django_components-0.95 → django_components-0.97}/tests/test_command_startcomponent.py +0 -0
  53. {django_components-0.95 → django_components-0.97}/tests/test_component_as_view.py +0 -0
  54. {django_components-0.95 → django_components-0.97}/tests/test_component_media.py +0 -0
  55. {django_components-0.95 → django_components-0.97}/tests/test_dependency_rendering.py +0 -0
  56. {django_components-0.95 → django_components-0.97}/tests/test_expression.py +0 -0
  57. {django_components-0.95 → django_components-0.97}/tests/test_registry.py +0 -0
  58. {django_components-0.95 → django_components-0.97}/tests/test_safer_staticfiles.py +0 -0
  59. {django_components-0.95 → django_components-0.97}/tests/test_settings.py +0 -0
  60. {django_components-0.95 → django_components-0.97}/tests/test_tag_formatter.py +0 -0
  61. {django_components-0.95 → django_components-0.97}/tests/test_template_loader.py +0 -0
  62. {django_components-0.95 → django_components-0.97}/tests/test_template_parser.py +0 -0
  63. {django_components-0.95 → django_components-0.97}/tests/test_templatetags.py +0 -0
  64. {django_components-0.95 → django_components-0.97}/tests/test_templatetags_component.py +0 -0
  65. {django_components-0.95 → django_components-0.97}/tests/test_templatetags_provide.py +0 -0
  66. {django_components-0.95 → django_components-0.97}/tests/test_templatetags_templating.py +0 -0
  67. {django_components-0.95 → django_components-0.97}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: django_components
3
- Version: 0.95
3
+ Version: 0.97
4
4
  Summary: A way to create simple reusable template components in Django.
5
5
  Author-email: Emil Stenström <emil@emilstenstrom.se>
6
6
  License: MIT
@@ -56,7 +56,7 @@ And this is what gets rendered (plus the CSS and Javascript you've specified):
56
56
  <div class="calendar-component">Today's date is <span>2015-06-19</span></div>
57
57
  ```
58
58
 
59
- [See the example project](./sampleproject) or read on to learn about the details!
59
+ [See the example project](https://github.com/EmilStenstrom/django-components/tree/master/sampleproject) or read on to learn about the details!
60
60
 
61
61
  ## Table of Contents
62
62
 
@@ -69,6 +69,7 @@ And this is what gets rendered (plus the CSS and Javascript you've specified):
69
69
  - [Use components in templates](#use-components-in-templates)
70
70
  - [Use components outside of templates](#use-components-outside-of-templates)
71
71
  - [Use components as views](#use-components-as-views)
72
+ - [Typing and validating components](#typing-and-validating-components)
72
73
  - [Pre-defined components](#pre-defined-components)
73
74
  - [Registering components](#registering-components)
74
75
  - [Autodiscovery](#autodiscovery)
@@ -77,7 +78,9 @@ And this is what gets rendered (plus the CSS and Javascript you've specified):
77
78
  - [Rendering HTML attributes](#rendering-html-attributes)
78
79
  - [Template tag syntax](#template-tag-syntax)
79
80
  - [Prop drilling and dependency injection (provide / inject)](#prop-drilling-and-dependency-injection-provide--inject)
81
+ - [Component hooks](#component-hooks)
80
82
  - [Component context and scope](#component-context-and-scope)
83
+ - [Pre-defined template variables](#pre-defined-template-variables)
81
84
  - [Customizing component tags with TagFormatter](#customizing-component-tags-with-tagformatter)
82
85
  - [Defining HTML/JS/CSS files](#defining-htmljscss-files)
83
86
  - [Rendering JS/CSS dependencies](#rendering-jscss-dependencies)
@@ -92,6 +95,18 @@ And this is what gets rendered (plus the CSS and Javascript you've specified):
92
95
 
93
96
  ## Release notes
94
97
 
98
+ **Version 0.97**
99
+ - Fixed template caching. You can now also manually create cached templates with [`cached_template()`](#template_cache_size---tune-the-template-cache)
100
+ - The previously undocumented `get_template` was made private.
101
+ - In it's place, there's a new `get_template`, which supersedes `get_template_string` (will be removed in v1). The new `get_template` is the same as `get_template_string`, except
102
+ it allows to return either a string or a Template instance.
103
+ - You now must use only one of `template`, `get_template`, `template_name`, or `get_template_name`.
104
+
105
+ **Version 0.96**
106
+ - Run-time type validation for Python 3.11+ - If the `Component` class is typed, e.g. `Component[Args, Kwargs, ...]`, the args, kwargs, slots, and data are validated against the given types. (See [Runtime input validation with types](#runtime-input-validation-with-types))
107
+ - Render hooks - Set `on_render_before` and `on_render_after` methods on `Component` to intercept or modify the template or context before rendering, or the rendered result afterwards. (See [Component hooks](#component-hooks))
108
+ - `component_vars.is_filled` context variable can be accessed from within `on_render_before` and `on_render_after` hooks as `self.is_filled.my_slot`
109
+
95
110
  **Version 0.95**
96
111
  - Added support for dynamic components, where the component name is passed as a variable. (See [Dynamic components](#dynamic-components))
97
112
  - Changed `Component.input` to raise `RuntimeError` if accessed outside of render context. Previously it returned `None` if unset.
@@ -109,7 +124,7 @@ And this is what gets rendered (plus the CSS and Javascript you've specified):
109
124
  🚨📢 **Version 0.92**
110
125
  - BREAKING CHANGE: `Component` class is no longer a subclass of `View`. To configure the `View` class, set the `Component.View` nested class. HTTP methods like `get` or `post` can still be defined directly on `Component` class, and `Component.as_view()` internally calls `Component.View.as_view()`. (See [Modifying the View class](#modifying-the-view-class))
111
126
 
112
- - The inputs (args, kwargs, slots, context, ...) that you pass to `Component.render()` can be accessed from within `get_context_data`, `get_template_string` and `get_template_name` via `self.input`. (See [Accessing data passed to the component](#accessing-data-passed-to-the-component))
127
+ - The inputs (args, kwargs, slots, context, ...) that you pass to `Component.render()` can be accessed from within `get_context_data`, `get_template` and `get_template_name` via `self.input`. (See [Accessing data passed to the component](#accessing-data-passed-to-the-component))
113
128
 
114
129
  - Typing: `Component` class supports generics that specify types for `Component.render` (See [Adding type hints with Generics](#adding-type-hints-with-generics))
115
130
 
@@ -235,7 +250,7 @@ python manage.py runserver
235
250
  ```
236
251
 
237
252
  For a step-by-step guide on deploying production server with static files,
238
- [see the demo project](./sampleproject/README.md).
253
+ [see the demo project](https://github.com/EmilStenstrom/django-components/tree/master/sampleproject).
239
254
 
240
255
  ## Installation
241
256
 
@@ -399,11 +414,13 @@ from django_components import Component, register
399
414
  @register("calendar")
400
415
  class Calendar(Component):
401
416
  # Templates inside `[your apps]/components` dir and `[project root]/components` dir
402
- # will be automatically found. To customize which template to use based on context
403
- # you can override method `get_template_name` instead of specifying `template_name`.
417
+ # will be automatically found.
404
418
  #
405
419
  # `template_name` can be relative to dir where `calendar.py` is, or relative to STATICFILES_DIRS
406
420
  template_name = "template.html"
421
+ # Or
422
+ def get_template_name(context):
423
+ return f"template-{context['name']}.html"
407
424
 
408
425
  # This component takes one parameter, a date string to show in the template
409
426
  def get_context_data(self, date):
@@ -656,58 +673,6 @@ MyComponent.render_to_response(
656
673
  )
657
674
  ```
658
675
 
659
- ### Adding type hints with Generics
660
-
661
- The `Component` class optionally accepts type parameters
662
- that allow you to specify the types of args, kwargs, slots, and
663
- data.
664
-
665
- ```py
666
- from typing import NotRequired, Tuple, TypedDict, SlotFunc
667
-
668
- # Positional inputs - Tuple
669
- Args = Tuple[int, str]
670
-
671
- # Kwargs inputs - Mapping
672
- class Kwargs(TypedDict):
673
- variable: str
674
- another: int
675
- maybe_var: NotRequired[int]
676
-
677
- # Data returned from `get_context_data` - Mapping
678
- class Data(TypedDict):
679
- variable: str
680
-
681
- # The data available to the `my_slot` scoped slot
682
- class MySlotData(TypedDict):
683
- value: int
684
-
685
- # Slot functions - Mapping
686
- class Slots(TypedDict):
687
- # Use SlotFunc for slot functions.
688
- # The generic specifies the `data` dictionary
689
- my_slot: NotRequired[SlotFunc[MySlotData]]
690
-
691
- class Button(Component[Args, Kwargs, Data, Slots]):
692
- def get_context_data(self, variable, another):
693
- return {
694
- "variable": variable,
695
- }
696
- ```
697
-
698
- When you then call `Component.render` or `Component.render_to_response`, you will get type hints:
699
-
700
- ```py
701
- Button.render(
702
- # Error: First arg must be `int`, got `float`
703
- args=(1.25, "abc"),
704
- # Error: Key "another" is missing
705
- kwargs={
706
- "variable": "text",
707
- },
708
- )
709
- ```
710
-
711
676
  ### Response class of `render_to_response`
712
677
 
713
678
  While `render` method returns a plain string, `render_to_response` wraps the rendered content in a "Response" class. By default, this is `django.http.HttpResponse`.
@@ -879,6 +844,182 @@ class MyComponent(Component):
879
844
  do_something_extra(request, *args, **kwargs)
880
845
  ```
881
846
 
847
+ ## Typing and validating components
848
+
849
+ ### Adding type hints with Generics
850
+
851
+ _New in version 0.92_
852
+
853
+ The `Component` class optionally accepts type parameters
854
+ that allow you to specify the types of args, kwargs, slots, and
855
+ data:
856
+
857
+ ```py
858
+ class Button(Component[Args, Kwargs, Data, Slots]):
859
+ ...
860
+ ```
861
+
862
+ - `Args` - Must be a `Tuple` or `Any`
863
+ - `Kwargs` - Must be a `TypedDict` or `Any`
864
+ - `Data` - Must be a `TypedDict` or `Any`
865
+ - `Slots` - Must be a `TypedDict` or `Any`
866
+
867
+ Here's a full example:
868
+
869
+ ```py
870
+ from typing import NotRequired, Tuple, TypedDict, SlotContent, SlotFunc
871
+
872
+ # Positional inputs
873
+ Args = Tuple[int, str]
874
+
875
+ # Kwargs inputs
876
+ class Kwargs(TypedDict):
877
+ variable: str
878
+ another: int
879
+ maybe_var: NotRequired[int] # May be ommited
880
+
881
+ # Data returned from `get_context_data`
882
+ class Data(TypedDict):
883
+ variable: str
884
+
885
+ # The data available to the `my_slot` scoped slot
886
+ class MySlotData(TypedDict):
887
+ value: int
888
+
889
+ # Slots
890
+ class Slots(TypedDict):
891
+ # Use SlotFunc for slot functions.
892
+ # The generic specifies the `data` dictionary
893
+ my_slot: NotRequired[SlotFunc[MySlotData]]
894
+ # SlotContent == Union[str, SafeString]
895
+ another_slot: SlotContent
896
+
897
+ class Button(Component[Args, Kwargs, Data, Slots]):
898
+ def get_context_data(self, variable, another):
899
+ return {
900
+ "variable": variable,
901
+ }
902
+ ```
903
+
904
+ When you then call `Component.render` or `Component.render_to_response`, you will get type hints:
905
+
906
+ ```py
907
+ Button.render(
908
+ # Error: First arg must be `int`, got `float`
909
+ args=(1.25, "abc"),
910
+ # Error: Key "another" is missing
911
+ kwargs={
912
+ "variable": "text",
913
+ },
914
+ )
915
+ ```
916
+
917
+ #### Usage for Python <3.11
918
+
919
+ On Python 3.8-3.10, use `typing_extensions`
920
+
921
+ ```py
922
+ from typing_extensions import TypedDict, NotRequired
923
+ ```
924
+
925
+ Additionally on Python 3.8-3.9, also import `annotations`:
926
+
927
+ ```py
928
+ from __future__ import annotations
929
+ ```
930
+
931
+ Moreover, on 3.10 and less, you may not be able to use `NotRequired`, and instead you will need to mark either all keys are required, or all keys as optional, using TypeDict's `total` kwarg.
932
+
933
+ [See PEP-655](https://peps.python.org/pep-0655) for more info.
934
+
935
+
936
+ ### Passing additional args or kwargs
937
+
938
+ You may have a function that supports any number of args or kwargs:
939
+
940
+ ```py
941
+ def get_context_data(self, *args, **kwargs):
942
+ ...
943
+ ```
944
+
945
+ This is not supported with the typed components.
946
+
947
+ As a workaround:
948
+ - For `*args`, set a positional argument that accepts a list of values:
949
+
950
+ ```py
951
+ # Tuple of one member of list of strings
952
+ Args = Tuple[List[str]]
953
+ ```
954
+
955
+ - For `*kwargs`, set a keyword argument that accepts a dictionary of values:
956
+
957
+ ```py
958
+ class Kwargs(TypedDict):
959
+ variable: str
960
+ another: int
961
+ # Pass any extra keys under `extra`
962
+ extra: Dict[str, any]
963
+ ```
964
+
965
+ ### Handling no args or no kwargs
966
+
967
+ To declare that a component accepts no Args, Kwargs, etc, you can use `EmptyTuple` and `EmptyDict` types:
968
+
969
+ ```py
970
+ from django_components import Component, EmptyDict, EmptyTuple
971
+
972
+ Args = EmptyTuple
973
+ Kwargs = Data = Slots = EmptyDict
974
+
975
+ class Button(Component[Args, Kwargs, Data, Slots]):
976
+ ...
977
+ ```
978
+
979
+ ### Runtime input validation with types
980
+
981
+ _New in version 0.96_
982
+
983
+ > NOTE: Kwargs, slots, and data validation is supported only for Python >=3.11
984
+
985
+ In Python 3.11 and later, when you specify the component types, you will get also runtime validation of the inputs you pass to `Component.render` or `Component.render_to_response`.
986
+
987
+ So, using the example from before, if you ignored the type errors and still ran the following code:
988
+
989
+ ```py
990
+ Button.render(
991
+ # Error: First arg must be `int`, got `float`
992
+ args=(1.25, "abc"),
993
+ # Error: Key "another" is missing
994
+ kwargs={
995
+ "variable": "text",
996
+ },
997
+ )
998
+ ```
999
+
1000
+ This would raise a `TypeError`:
1001
+
1002
+ ```txt
1003
+ Component 'Button' expected positional argument at index 0 to be <class 'int'>, got 1.25 of type <class 'float'>
1004
+ ```
1005
+
1006
+ In case you need to skip these errors, you can either set the faulty member to `Any`, e.g.:
1007
+
1008
+ ```py
1009
+ # Changed `int` to `Any`
1010
+ Args = Tuple[Any, str]
1011
+ ```
1012
+
1013
+ Or you can replace `Args` with `Any` altogether, to skip the validation of args:
1014
+
1015
+ ```py
1016
+ # Replaced `Args` with `Any`
1017
+ class Button(Component[Any, Kwargs, Data, Slots]):
1018
+ ...
1019
+ ```
1020
+
1021
+ Same applies to kwargs, data, and slots.
1022
+
882
1023
  ## Pre-defined components
883
1024
 
884
1025
  ### Dynamic components
@@ -1371,7 +1512,7 @@ This produces:
1371
1512
 
1372
1513
  _Added in version 0.26._
1373
1514
 
1374
- > NOTE: In version 0.70, `{% if_filled %}` tags were replaced with `{{ component_vars.is_filled }}` variables. If your slot name contained special characters, see the section "Accessing slot names with special characters".
1515
+ > NOTE: In version 0.70, `{% if_filled %}` tags were replaced with `{{ component_vars.is_filled }}` variables. If your slot name contained special characters, see the section [Accessing `is_filled` of slot names with special characters](#accessing-is_filled-of-slot-names-with-special-characters).
1375
1516
 
1376
1517
  In certain circumstances, you may want the behavior of slot filling to depend on
1377
1518
  whether or not a particular slot is filled.
@@ -1634,7 +1775,7 @@ When you call `Component.render` or `Component.render_to_response`, the inputs t
1634
1775
  This means that you can use `self.input` inside:
1635
1776
  - `get_context_data`
1636
1777
  - `get_template_name`
1637
- - `get_template_string`
1778
+ - `get_template`
1638
1779
 
1639
1780
  `self.input` is defined only for the duration of `Component.render`, and raises `RuntimeError` when called outside of this.
1640
1781
 
@@ -2456,6 +2597,88 @@ renders:
2456
2597
  <div>123</div>
2457
2598
  ```
2458
2599
 
2600
+ ## Component hooks
2601
+
2602
+ _New in version 0.96_
2603
+
2604
+ Component hooks are functions that allow you to intercept the rendering process at specific positions.
2605
+
2606
+ ### Available hooks
2607
+
2608
+ - `on_render_before`
2609
+
2610
+ ```py
2611
+ def on_render_before(
2612
+ self: Component,
2613
+ context: Context,
2614
+ template: Template
2615
+ ) -> None:
2616
+ ```
2617
+
2618
+ Hook that runs just before the component's template is rendered.
2619
+
2620
+ You can use this hook to access or modify the context or the template:
2621
+
2622
+ ```py
2623
+ def on_render_before(self, context, template) -> None:
2624
+ # Insert value into the Context
2625
+ context["from_on_before"] = ":)"
2626
+
2627
+ # Append text into the Template
2628
+ template.nodelist.append(TextNode("FROM_ON_BEFORE"))
2629
+ ```
2630
+
2631
+ - `on_render_after`
2632
+
2633
+ ```py
2634
+ def on_render_after(
2635
+ self: Component,
2636
+ context: Context,
2637
+ template: Template,
2638
+ content: str
2639
+ ) -> None | str | SafeString:
2640
+ ```
2641
+
2642
+ Hook that runs just after the component's template was rendered.
2643
+ It receives the rendered output as the last argument.
2644
+
2645
+ You can use this hook to access the context or the template, but modifying
2646
+ them won't have any effect.
2647
+
2648
+ To override the content that gets rendered, you can return a string or SafeString from this hook:
2649
+
2650
+ ```py
2651
+ def on_render_after(self, context, template, content):
2652
+ # Prepend text to the rendered content
2653
+ return "Chocolate cookie recipe: " + content
2654
+ ```
2655
+
2656
+ ### Component hooks example
2657
+
2658
+ You can use hooks together with [provide / inject](#how-to-use-provide--inject) to create components
2659
+ that accept a list of items via a slot.
2660
+
2661
+ In the example below, each `tab_item` component will be rendered on a separate tab page, but they are all defined in the default slot of the `tabs` component.
2662
+
2663
+ [See here for how it was done](https://github.com/EmilStenstrom/django-components/discussions/540)
2664
+
2665
+ ```django
2666
+ {% component "tabs" %}
2667
+ {% component "tab_item" header="Tab 1" %}
2668
+ <p>
2669
+ hello from tab 1
2670
+ </p>
2671
+ {% component "button" %}
2672
+ Click me!
2673
+ {% endcomponent %}
2674
+ {% endcomponent %}
2675
+
2676
+ {% component "tab_item" header="Tab 2" %}
2677
+ Hello this is tab 2
2678
+ {% endcomponent %}
2679
+ {% endcomponent %}
2680
+ ```
2681
+
2459
2682
  ## Component context and scope
2460
2683
 
2461
2684
  By default, context variables are passed down the template as in regular Django - deeper scopes can access the variables from the outer scopes. So if you have several nested forloops, then inside the deep-most loop you can access variables defined by all previous loops.
@@ -2474,6 +2697,24 @@ If you find yourself using the `only` modifier often, you can set the [context_b
2474
2697
 
2475
2698
  Components can also access the outer context in their context methods like `get_context_data` by accessing the property `self.outer_context`.
2476
2699
 
2700
+ ## Pre-defined template variables
2701
+
2702
+ Here is a list of all variables that are automatically available from within the component's template and `on_render_before` / `on_render_after` hooks.
2703
+
2704
+ - `component_vars.is_filled`
2705
+
2706
+ _New in version 0.70_
2707
+
2708
+ Dictonary describing which slots are filled (`True`) or are not (`False`).
2709
+
2710
+ Example:
2711
+
2712
+ ```django
2713
+ {% if component_vars.is_filled.my_slot %}
2714
+ {% slot "my_slot" / %}
2715
+ {% endif %}
2716
+ ```
2717
+
2477
2718
  ## Customizing component tags with TagFormatter
2478
2719
 
2479
2720
  _New in version 0.89_
@@ -2962,6 +3203,26 @@ COMPONENTS = {
2962
3203
  }
2963
3204
  ```
2964
3205
 
3206
+ If you want add templates to the cache yourself, you can use `cached_template()`:
3207
+
3208
+ ```py
3209
+ from django_components import cached_template
3210
+
3211
+ cached_template("Variable: {{ variable }}")
3212
+
3213
+ # You can optionally specify Template class, and other Template inputs:
3214
+ class MyTemplate(Template):
3215
+ pass
3216
+
3217
+ cached_template(
3218
+ "Variable: {{ variable }}",
3219
+ template_cls=MyTemplate,
3220
+ name=...
3221
+ origin=...
3222
+ engine=...
3223
+ )
3224
+ ```
3225
+
2965
3226
  ### `context_behavior` - Make components isolated (or not)
2966
3227
 
2967
3228
  > NOTE: `context_behavior` and `slot_context_behavior` options were merged in v0.70.