diff --git a/dev/reference/api/index.html b/dev/reference/api/index.html index 5eab30dc..7dd1c600 100644 --- a/dev/reference/api/index.html +++ b/dev/reference/api/index.html @@ -1,6 +1,6 @@ Api - Django-Components
Skip to content

API¤

Component ¤

Component(registered_name: Optional[str] = None, outer_context: Optional[Context] = None, registry: Optional[ComponentRegistry] = None)
 

Methods:

Attributes:

Media class-attribute instance-attribute ¤

See source code

Defines JS and CSS media files associated with this component.

This Media class behaves similarly to Django's Media class:

  • Paths are generally handled as static file paths, and resolved URLs are rendered to HTML with media_class.render_js() or media_class.render_css().
  • A path that starts with http, https, or / is considered a URL, skipping the static file resolution. This path is still rendered to HTML with media_class.render_js() or media_class.render_css().
  • A SafeString (with __html__ method) is considered an already-formatted HTML tag, skipping both static file resolution and rendering with media_class.render_js() or media_class.render_css().
  • You can set extend to configure whether to inherit JS / CSS from parent components. See Controlling Media Inheritance.

However, there's a few differences from Django's Media class:

  1. Our Media class accepts various formats for the JS and CSS files: either a single file, a list, or (CSS-only) a dictonary (See ComponentMediaInput).
  2. Individual JS / CSS files can be any of str, bytes, Path, SafeString, or a function (See ComponentMediaInputPath).

Example:

class MyTable(Component):
+

See source code

Defines JS and CSS media files associated with this component.

This Media class behaves similarly to Django's Media class:

  • Paths are generally handled as static file paths, and resolved URLs are rendered to HTML with media_class.render_js() or media_class.render_css().
  • A path that starts with http, https, or / is considered a URL, skipping the static file resolution. This path is still rendered to HTML with media_class.render_js() or media_class.render_css().
  • A SafeString (with __html__ method) is considered an already-formatted HTML tag, skipping both static file resolution and rendering with media_class.render_js() or media_class.render_css().
  • You can set extend to configure whether to inherit JS / CSS from parent components. See Controlling Media Inheritance.

However, there's a few differences from Django's Media class:

  1. Our Media class accepts various formats for the JS and CSS files: either a single file, a list, or (CSS-only) a dictonary (See ComponentMediaInput).
  2. Individual JS / CSS files can be any of str, bytes, Path, SafeString, or a function (See ComponentMediaInputPath).

Example:

class MyTable(Component):
     class Media:
         js = [
             "path/to/script.js",
@@ -15,14 +15,14 @@
         }
 

View class-attribute instance-attribute ¤

css class-attribute instance-attribute ¤

css: Optional[str] = None
-

See source code

Main CSS associated with this component inlined as string.

Only one of css or css_file must be defined.

Example:

class MyComponent(Component):
+

See source code

Main CSS associated with this component inlined as string.

Only one of css or css_file must be defined.

Example:

class MyComponent(Component):
     css = """
     .my-class {
         color: red;
     }
     """
 

css_file class-attribute instance-attribute ¤

css_file: Optional[str] = None
-

See source code

Main CSS associated with this component as file path.

The filepath must be either:

  • Relative to the directory where the Component's Python file is defined.
  • Relative to one of the component directories, as set by COMPONENTS.dirs or COMPONENTS.app_dirs (e.g. <root>/components/).
  • Relative to the staticfiles directories, as set by Django's STATICFILES_DIRS setting (e.g. <root>/static/).

When you create a Component class with css_file, these will happen:

  1. If the file path is relative to the directory where the component's Python file is, the path is resolved.
  2. The file is read and its contents is set to Component.css.

Only one of css or css_file must be defined.

Example:

path/to/style.css
.my-class {
+

See source code

Main CSS associated with this component as file path.

The filepath must be either:

  • Relative to the directory where the Component's Python file is defined.
  • Relative to one of the component directories, as set by COMPONENTS.dirs or COMPONENTS.app_dirs (e.g. <root>/components/).
  • Relative to the staticfiles directories, as set by Django's STATICFILES_DIRS setting (e.g. <root>/static/).

When you create a Component class with css_file, these will happen:

  1. If the file path is relative to the directory where the component's Python file is, the path is resolved.
  2. The file is read and its contents is set to Component.css.

Only one of css or css_file must be defined.

Example:

path/to/style.css
.my-class {
     color: red;
 }
 
path/to/component.py
class MyComponent(Component):
@@ -34,7 +34,7 @@
 #     color: red;
 # };
 

id property ¤

id: str
-

See source code

This ID is unique for every time a Component.render() (or equivalent) is called (AKA "render ID").

This is useful for logging or debugging.

Raises RuntimeError if accessed outside of rendering execution.

A single render ID has a chance of collision 1 in 3.3M. However, due to birthday paradox, the chance of collision increases when approaching ~1,000 render IDs.

Thus, there is a soft-cap of 1,000 components rendered on a single page.

If you need to more than that, please open an issue on GitHub.

Example:

class MyComponent(Component):
+

See source code

This ID is unique for every time a Component.render() (or equivalent) is called (AKA "render ID").

This is useful for logging or debugging.

Raises RuntimeError if accessed outside of rendering execution.

A single render ID has a chance of collision 1 in 3.3M. However, due to birthday paradox, the chance of collision increases when approaching ~1,000 render IDs.

Thus, there is a soft-cap of 1,000 components rendered on a single page.

If you need to more than that, please open an issue on GitHub.

Example:

class MyComponent(Component):
     def get_context_data(self):
         print(f"Rendering '{self.id}'")
         return {}
@@ -42,19 +42,19 @@
 MyComponent.render()
 # Rendering 'ab3c4d'
 

input property ¤

input: RenderInput[ArgsType, KwargsType, SlotsType]
-

See source code

Input holds the data (like arg, kwargs, slots) that were passsed to the current execution of the render method.

is_filled property ¤

is_filled: SlotIsFilled
-

See source code

Dictionary describing which slots have or have not been filled.

This attribute is available for use only within the template as {{ component_vars.is_filled.slot_name }}, and within on_render_before and on_render_after hooks.

js class-attribute instance-attribute ¤

js: Optional[str] = None
-

See source code

Main JS associated with this component inlined as string.

Only one of js or js_file must be defined.

Example:

class MyComponent(Component):
+

See source code

Input holds the data (like arg, kwargs, slots) that were passsed to the current execution of the render method.

is_filled property ¤

is_filled: SlotIsFilled
+

See source code

Dictionary describing which slots have or have not been filled.

This attribute is available for use only within the template as {{ component_vars.is_filled.slot_name }}, and within on_render_before and on_render_after hooks.

js class-attribute instance-attribute ¤

js: Optional[str] = None
+

See source code

Main JS associated with this component inlined as string.

Only one of js or js_file must be defined.

Example:

class MyComponent(Component):
     js = "console.log('Hello, World!');"
 

js_file class-attribute instance-attribute ¤

js_file: Optional[str] = None
-

See source code

Main JS associated with this component as file path.

The filepath must be either:

  • Relative to the directory where the Component's Python file is defined.
  • Relative to one of the component directories, as set by COMPONENTS.dirs or COMPONENTS.app_dirs (e.g. <root>/components/).
  • Relative to the staticfiles directories, as set by Django's STATICFILES_DIRS setting (e.g. <root>/static/).

When you create a Component class with js_file, these will happen:

  1. If the file path is relative to the directory where the component's Python file is, the path is resolved.
  2. The file is read and its contents is set to Component.js.

Only one of js or js_file must be defined.

Example:

path/to/script.js
console.log('Hello, World!');
+

See source code

Main JS associated with this component as file path.

The filepath must be either:

  • Relative to the directory where the Component's Python file is defined.
  • Relative to one of the component directories, as set by COMPONENTS.dirs or COMPONENTS.app_dirs (e.g. <root>/components/).
  • Relative to the staticfiles directories, as set by Django's STATICFILES_DIRS setting (e.g. <root>/static/).

When you create a Component class with js_file, these will happen:

  1. If the file path is relative to the directory where the component's Python file is, the path is resolved.
  2. The file is read and its contents is set to Component.js.

Only one of js or js_file must be defined.

Example:

path/to/script.js
console.log('Hello, World!');
 
path/to/component.py
class MyComponent(Component):
     js_file = "path/to/script.js"
 
 print(MyComponent.js)
 # Output: console.log('Hello, World!');
 

media class-attribute instance-attribute ¤

media: Optional[Media] = None
-

See source code

Normalized definition of JS and CSS media files associated with this component. None if Component.Media is not defined.

This field is generated from Component.media_class.

Read more on Accessing component's HTML / JS / CSS.

Example:

class MyComponent(Component):
+

See source code

Normalized definition of JS and CSS media files associated with this component. None if Component.Media is not defined.

This field is generated from Component.media_class.

Read more on Accessing component's HTML / JS / CSS.

Example:

class MyComponent(Component):
     class Media:
         js = "path/to/script.js"
         css = "path/to/style.css"
@@ -64,7 +64,7 @@
 # <script src="/static/path/to/script.js"></script>
 # <link href="/static/path/to/style.css" media="all" rel="stylesheet">
 

media_class class-attribute instance-attribute ¤

media_class: Type[Media] = Media
-

See source code

Set the Media class that will be instantiated with the JS and CSS media files from Component.Media.

This is useful when you want to customize the behavior of the media files, like customizing how the JS or CSS files are rendered into <script> or <link> HTML tags. Read more in Defining HTML / JS / CSS files.

Example:

class MyTable(Component):
+

See source code

Set the Media class that will be instantiated with the JS and CSS media files from Component.Media.

This is useful when you want to customize the behavior of the media files, like customizing how the JS or CSS files are rendered into <script> or <link> HTML tags. Read more in Defining HTML / JS / CSS files.

Example:

class MyTable(Component):
     class Media:
         js = "path/to/script.js"
         css = "path/to/style.css"
@@ -75,25 +75,25 @@
 

registered_name instance-attribute ¤

registered_name: Optional[str] = registered_name
 

registry instance-attribute ¤

registry = registry or registry
 

response_class class-attribute instance-attribute ¤

response_class = HttpResponse
-

See source code

This allows to configure what class is used to generate response from render_to_response

template class-attribute instance-attribute ¤

template: Optional[Union[str, Template]] = None
-

See source code

Inlined Django template associated with this component. Can be a plain string or a Template instance.

Only one of template_file, get_template_name, template or get_template must be defined.

Example:

class MyComponent(Component):
+

See source code

This allows to configure what class is used to generate response from render_to_response

template class-attribute instance-attribute ¤

template: Optional[Union[str, Template]] = None
+

See source code

Inlined Django template associated with this component. Can be a plain string or a Template instance.

Only one of template_file, get_template_name, template or get_template must be defined.

Example:

class MyComponent(Component):
     template = "Hello, {{ name }}!"
 
     def get_context_data(self):
         return {"name": "World"}
 

template_file class-attribute instance-attribute ¤

template_file: Optional[str] = None
-

See source code

Filepath to the Django template associated with this component.

The filepath must be either:

  • Relative to the directory where the Component's Python file is defined.
  • Relative to one of the component directories, as set by COMPONENTS.dirs or COMPONENTS.app_dirs (e.g. <root>/components/).
  • Relative to the template directories, as set by Django's TEMPLATES setting (e.g. <root>/templates/).

Only one of template_file, get_template_name, template or get_template must be defined.

Example:

class MyComponent(Component):
+

See source code

Filepath to the Django template associated with this component.

The filepath must be either:

  • Relative to the directory where the Component's Python file is defined.
  • Relative to one of the component directories, as set by COMPONENTS.dirs or COMPONENTS.app_dirs (e.g. <root>/components/).
  • Relative to the template directories, as set by Django's TEMPLATES setting (e.g. <root>/templates/).

Only one of template_file, get_template_name, template or get_template must be defined.

Example:

class MyComponent(Component):
     template_file = "path/to/template.html"
 
     def get_context_data(self):
         return {"name": "World"}
 

template_name instance-attribute ¤

template_name: Optional[str]
-

See source code

Alias for template_file.

For historical reasons, django-components used template_name to align with Django's TemplateView.

template_file was introduced to align with js/js_file and css/css_file.

Setting and accessing this attribute is proxied to template_file.

as_view classmethod ¤

as_view(**initkwargs: Any) -> ViewFn
-

See source code

Shortcut for calling Component.View.as_view and passing component instance to it.

get_context_data ¤

get_context_data(*args: Any, **kwargs: Any) -> DataType
+

See source code

Alias for template_file.

For historical reasons, django-components used template_name to align with Django's TemplateView.

template_file was introduced to align with js/js_file and css/css_file.

Setting and accessing this attribute is proxied to template_file.

as_view classmethod ¤

as_view(**initkwargs: Any) -> ViewFn
+

See source code

Shortcut for calling Component.View.as_view and passing component instance to it.

get_context_data ¤

get_context_data(*args: Any, **kwargs: Any) -> DataType
 

get_template ¤

get_template(context: Context) -> Optional[Union[str, Template]]
-

See source code

Inlined Django template associated with this component. Can be a plain string or a Template instance.

Only one of template_file, get_template_name, template or get_template must be defined.

get_template_name ¤

get_template_name(context: Context) -> Optional[str]
-

See source code

Filepath to the Django template associated with this component.

The filepath must be relative to either the file where the component class was defined, or one of the roots of STATIFILES_DIRS.

Only one of template_file, get_template_name, template or get_template must be defined.

inject ¤

inject(key: str, default: Optional[Any] = None) -> Any
-

See source code

Use this method to retrieve the data that was passed to a {% provide %} tag with the corresponding key.

To retrieve the data, inject() must be called inside a component that's inside the {% provide %} tag.

You may also pass a default that will be used if the provide tag with given key was NOT found.

This method mut be used inside the get_context_data() method and raises an error if called elsewhere.

Example:

Given this template:

{% provide "provider" hello="world" %}
+

See source code

Inlined Django template associated with this component. Can be a plain string or a Template instance.

Only one of template_file, get_template_name, template or get_template must be defined.

get_template_name ¤

get_template_name(context: Context) -> Optional[str]
+

See source code

Filepath to the Django template associated with this component.

The filepath must be relative to either the file where the component class was defined, or one of the roots of STATIFILES_DIRS.

Only one of template_file, get_template_name, template or get_template must be defined.

inject ¤

inject(key: str, default: Optional[Any] = None) -> Any
+

See source code

Use this method to retrieve the data that was passed to a {% provide %} tag with the corresponding key.

To retrieve the data, inject() must be called inside a component that's inside the {% provide %} tag.

You may also pass a default that will be used if the provide tag with given key was NOT found.

This method mut be used inside the get_context_data() method and raises an error if called elsewhere.

Example:

Given this template:

{% provide "provider" hello="world" %}
     {% component "my_comp" %}
     {% endcomponent %}
 {% endprovide %}
@@ -107,8 +107,8 @@
         return {"data": data}
 

This renders into:

hi world!
 

As the {{ data.hello }} is taken from the "provider".

on_render_after ¤

on_render_after(context: Context, template: Template, content: str) -> Optional[SlotResult]
-

See source code

Hook that runs just after the component's template was rendered. It receives the rendered output as the last argument.

You can use this hook to access the context or the template, but modifying them won't have any effect.

To override the content that gets rendered, you can return a string or SafeString from this hook.

on_render_before ¤

on_render_before(context: Context, template: Template) -> None
-

See source code

Hook that runs just before the component's template is rendered.

You can use this hook to access or modify the context or the template.

render classmethod ¤

render(
+

See source code

Hook that runs just after the component's template was rendered. It receives the rendered output as the last argument.

You can use this hook to access the context or the template, but modifying them won't have any effect.

To override the content that gets rendered, you can return a string or SafeString from this hook.

on_render_before ¤

on_render_before(context: Context, template: Template) -> None
+

See source code

Hook that runs just before the component's template is rendered.

You can use this hook to access or modify the context or the template.

render classmethod ¤

render(
     context: Optional[Union[Dict[str, Any], Context]] = None,
     args: Optional[ArgsType] = None,
     kwargs: Optional[KwargsType] = None,
@@ -118,7 +118,7 @@
     render_dependencies: bool = True,
     request: Optional[HttpRequest] = None,
 ) -> str
-

See source code

Render the component into a string.

Inputs: - args - Positional args for the component. This is the same as calling the component as {% component "my_comp" arg1 arg2 ... %} - kwargs - Kwargs for the component. This is the same as calling the component as {% component "my_comp" key1=val1 key2=val2 ... %} - slots - Component slot fills. This is the same as pasing {% fill %} tags to the component. Accepts a dictionary of { slot_name: slot_content } where slot_content can be a string or render function. - escape_slots_content - Whether the content from slots should be escaped. - context - A context (dictionary or Django's Context) within which the component is rendered. The keys on the context can be accessed from within the template. - NOTE: In "isolated" mode, context is NOT accessible, and data MUST be passed via component's args and kwargs. - type - Configure how to handle JS and CSS dependencies. - "document" (default) - JS dependencies are inserted into {% component_js_dependencies %}, or to the end of the <body> tag. CSS dependencies are inserted into {% component_css_dependencies %}, or the end of the <head> tag. - render_dependencies - Set this to False if you want to insert the resulting HTML into another component. - request - The request object. This is only required when needing to use RequestContext, e.g. to enable template context_processors. Unused if context is already an instance of Context Example:

MyComponent.render(
+

See source code

Render the component into a string.

Inputs: - args - Positional args for the component. This is the same as calling the component as {% component "my_comp" arg1 arg2 ... %} - kwargs - Kwargs for the component. This is the same as calling the component as {% component "my_comp" key1=val1 key2=val2 ... %} - slots - Component slot fills. This is the same as pasing {% fill %} tags to the component. Accepts a dictionary of { slot_name: slot_content } where slot_content can be a string or render function. - escape_slots_content - Whether the content from slots should be escaped. - context - A context (dictionary or Django's Context) within which the component is rendered. The keys on the context can be accessed from within the template. - NOTE: In "isolated" mode, context is NOT accessible, and data MUST be passed via component's args and kwargs. - type - Configure how to handle JS and CSS dependencies. - "document" (default) - JS dependencies are inserted into {% component_js_dependencies %}, or to the end of the <body> tag. CSS dependencies are inserted into {% component_css_dependencies %}, or the end of the <head> tag. - render_dependencies - Set this to False if you want to insert the resulting HTML into another component. - request - The request object. This is only required when needing to use RequestContext, e.g. to enable template context_processors. Unused if context is already an instance of Context Example:

MyComponent.render(
     args=[1, "two", {}],
     kwargs={
         "key": 123,
@@ -140,7 +140,7 @@
     *response_args: Any,
     **response_kwargs: Any
 ) -> HttpResponse
-

See source code

Render the component and wrap the content in the response class.

The response class is taken from Component.response_class. Defaults to django.http.HttpResponse.

This is the interface for the django.views.View class which allows us to use components as Django views with component.as_view().

Inputs: - args - Positional args for the component. This is the same as calling the component as {% component "my_comp" arg1 arg2 ... %} - kwargs - Kwargs for the component. This is the same as calling the component as {% component "my_comp" key1=val1 key2=val2 ... %} - slots - Component slot fills. This is the same as pasing {% fill %} tags to the component. Accepts a dictionary of { slot_name: slot_content } where slot_content can be a string or render function. - escape_slots_content - Whether the content from slots should be escaped. - context - A context (dictionary or Django's Context) within which the component is rendered. The keys on the context can be accessed from within the template. - NOTE: In "isolated" mode, context is NOT accessible, and data MUST be passed via component's args and kwargs. - type - Configure how to handle JS and CSS dependencies. - "document" (default) - JS dependencies are inserted into {% component_js_dependencies %}, or to the end of the <body> tag. CSS dependencies are inserted into {% component_css_dependencies %}, or the end of the <head> tag. - request - The request object. This is only required when needing to use RequestContext, e.g. to enable template context_processors. Unused if context is already an instance of Context

Any additional args and kwargs are passed to the response_class.

Example:

MyComponent.render_to_response(
+

See source code

Render the component and wrap the content in the response class.

The response class is taken from Component.response_class. Defaults to django.http.HttpResponse.

This is the interface for the django.views.View class which allows us to use components as Django views with component.as_view().

Inputs: - args - Positional args for the component. This is the same as calling the component as {% component "my_comp" arg1 arg2 ... %} - kwargs - Kwargs for the component. This is the same as calling the component as {% component "my_comp" key1=val1 key2=val2 ... %} - slots - Component slot fills. This is the same as pasing {% fill %} tags to the component. Accepts a dictionary of { slot_name: slot_content } where slot_content can be a string or render function. - escape_slots_content - Whether the content from slots should be escaped. - context - A context (dictionary or Django's Context) within which the component is rendered. The keys on the context can be accessed from within the template. - NOTE: In "isolated" mode, context is NOT accessible, and data MUST be passed via component's args and kwargs. - type - Configure how to handle JS and CSS dependencies. - "document" (default) - JS dependencies are inserted into {% component_js_dependencies %}, or to the end of the <body> tag. CSS dependencies are inserted into {% component_css_dependencies %}, or the end of the <head> tag. - request - The request object. This is only required when needing to use RequestContext, e.g. to enable template context_processors. Unused if context is already an instance of Context

Any additional args and kwargs are passed to the response_class.

Example:

MyComponent.render_to_response(
     args=[1, "two", {}],
     kwargs={
         "key": 123,
@@ -300,9 +300,9 @@
 registry.register("button", ButtonComponent)
 # Then unregister
 registry.unregister("button")
-

ComponentVars ¤

Bases: tuple

See source code

Type for the variables available inside the component templates.

All variables here are scoped under component_vars., so e.g. attribute is_filled on this class is accessible inside the template as:

{{ component_vars.is_filled }}
+

ComponentVars ¤

Bases: tuple

See source code

Type for the variables available inside the component templates.

All variables here are scoped under component_vars., so e.g. attribute is_filled on this class is accessible inside the template as:

{{ component_vars.is_filled }}
 

Attributes:

is_filled instance-attribute ¤

is_filled: Dict[str, bool]
-

See source code

Dictonary describing which component slots are filled (True) or are not (False).

New in version 0.70

Use as {{ component_vars.is_filled }}

Example:

{# Render wrapping HTML only if the slot is defined #}
+

See source code

Dictonary describing which component slots are filled (True) or are not (False).

New in version 0.70

Use as {{ component_vars.is_filled }}

Example:

{# Render wrapping HTML only if the slot is defined #}
 {% if component_vars.is_filled.my_slot %}
     <div class="slot-wrapper">
         {% slot "my_slot" / %}
@@ -314,7 +314,7 @@
             "my_slot_filled": "my_slot" in self.input.slots
         }
 

ComponentView ¤

ComponentView(component: Component, **kwargs: Any)
-

Bases: django.views.generic.base.View

See source code

Subclass of django.views.View where the Component instance is available via self.component.

Attributes:

component class-attribute instance-attribute ¤

component = component
+

Bases: django.views.generic.base.View

See source code

Subclass of django.views.View where the Component instance is available via self.component.

Attributes:

component class-attribute instance-attribute ¤

component = component
 

ComponentsSettings ¤

Bases: tuple

See source code

Settings available for django_components.

Example:

COMPONENTS = ComponentsSettings(
     autodiscover=False,
     dirs = [BASE_DIR / "components"],
diff --git a/dev/reference/template_tags/index.html b/dev/reference/template_tags/index.html
index 1f5f3018..76e465db 100644
--- a/dev/reference/template_tags/index.html
+++ b/dev/reference/template_tags/index.html
@@ -1,7 +1,7 @@
  Template tags - Django-Components      

Template tags¤

All following template tags are defined in

django_components.templatetags.component_tags

Import as

{% load component_tags %}
 

component¤

{% component *args: Any, **kwargs: Any [only] %}
 {% endcomponent %}
-

See source code

Renders one of the components that was previously registered with @register() decorator.

Args:

  • name (str, required): Registered name of the component to render
  • All other args and kwargs are defined based on the component itself.

If you defined a component "my_table"

from django_component import Component, register
+

See source code

Renders one of the components that was previously registered with @register() decorator.

Args:

  • name (str, required): Registered name of the component to render
  • All other args and kwargs are defined based on the component itself.

If you defined a component "my_table"

from django_component import Component, register
 
 @register("my_table")
 class MyTable(Component):
@@ -39,10 +39,10 @@
 {% endcomponent %}
 

Isolating components¤

By default, components behave similarly to Django's {% include %}, and the template inside the component has access to the variables defined in the outer template.

You can selectively isolate a component, using the only flag, so that the inner template can access only the data that was explicitly passed to it:

{% component "name" positional_arg keyword_arg=value ... only %}
 

component_css_dependencies¤

{% component_css_dependencies  %}
-

See source code

Marks location where CSS link tags should be rendered after the whole HTML has been generated.

Generally, this should be inserted into the <head> tag of the HTML.

If the generated HTML does NOT contain any {% component_css_dependencies %} tags, CSS links are by default inserted into the <head> tag of the HTML. (See JS and CSS output locations)

Note that there should be only one {% component_css_dependencies %} for the whole HTML document. If you insert this tag multiple times, ALL CSS links will be duplicately inserted into ALL these places.

component_js_dependencies¤

{% component_js_dependencies  %}
-

See source code

Marks location where JS link tags should be rendered after the whole HTML has been generated.

Generally, this should be inserted at the end of the <body> tag of the HTML.

If the generated HTML does NOT contain any {% component_js_dependencies %} tags, JS scripts are by default inserted at the end of the <body> tag of the HTML. (See JS and CSS output locations)

Note that there should be only one {% component_js_dependencies %} for the whole HTML document. If you insert this tag multiple times, ALL JS scripts will be duplicately inserted into ALL these places.

fill¤

{% fill name: str, *, data: Optional[str] = None, default: Optional[str] = None %}
+

See source code

Marks location where CSS link tags should be rendered after the whole HTML has been generated.

Generally, this should be inserted into the <head> tag of the HTML.

If the generated HTML does NOT contain any {% component_css_dependencies %} tags, CSS links are by default inserted into the <head> tag of the HTML. (See JS and CSS output locations)

Note that there should be only one {% component_css_dependencies %} for the whole HTML document. If you insert this tag multiple times, ALL CSS links will be duplicately inserted into ALL these places.

component_js_dependencies¤

{% component_js_dependencies  %}
+

See source code

Marks location where JS link tags should be rendered after the whole HTML has been generated.

Generally, this should be inserted at the end of the <body> tag of the HTML.

If the generated HTML does NOT contain any {% component_js_dependencies %} tags, JS scripts are by default inserted at the end of the <body> tag of the HTML. (See JS and CSS output locations)

Note that there should be only one {% component_js_dependencies %} for the whole HTML document. If you insert this tag multiple times, ALL JS scripts will be duplicately inserted into ALL these places.

fill¤

{% fill name: str, *, data: Optional[str] = None, default: Optional[str] = None %}
 {% endfill %}
-

See source code

Use this tag to insert content into component's slots.

{% fill %} tag may be used only within a {% component %}..{% endcomponent %} block. Runtime checks should prohibit other usages.

Args:

  • name (str, required): Name of the slot to insert this content into. Use "default" for the default slot.
  • default (str, optional): This argument allows you to access the original content of the slot under the specified variable name. See Accessing original content of slots
  • data (str, optional): This argument allows you to access the data passed to the slot under the specified variable name. See Scoped slots

Examples:

Basic usage:

{% component "my_table" %}
+

See source code

Use this tag to insert content into component's slots.

{% fill %} tag may be used only within a {% component %}..{% endcomponent %} block. Runtime checks should prohibit other usages.

Args:

  • name (str, required): Name of the slot to insert this content into. Use "default" for the default slot.
  • default (str, optional): This argument allows you to access the original content of the slot under the specified variable name. See Accessing original content of slots
  • data (str, optional): This argument allows you to access the data passed to the slot under the specified variable name. See Scoped slots

Examples:

Basic usage:

{% component "my_table" %}
   {% fill "pagination" %}
     < 1 | 2 | 3 >
   {% endfill %}
@@ -84,7 +84,7 @@
   {% endfill %}
 {% endcomponent %}
 

html_attrs¤

{% html_attrs attrs: Optional[Dict] = None, defaults: Optional[Dict] = None, **kwargs: Any %}
-

See source code

Generate HTML attributes (key="value"), combining data from multiple sources, whether its template variables or static text.

It is designed to easily merge HTML attributes passed from outside with the internal. See how to in Passing HTML attributes to components.

Args:

  • attrs (dict, optional): Optional dictionary that holds HTML attributes. On conflict, overrides values in the default dictionary.
  • default (str, optional): Optional dictionary that holds HTML attributes. On conflict, is overriden with values in the attrs dictionary.
  • Any extra kwargs will be appended to the corresponding keys

The attributes in attrs and defaults are merged and resulting dict is rendered as HTML attributes (key="value").

Extra kwargs (key=value) are concatenated to existing keys. So if we have

attrs = {"class": "my-class"}
+

See source code

Generate HTML attributes (key="value"), combining data from multiple sources, whether its template variables or static text.

It is designed to easily merge HTML attributes passed from outside with the internal. See how to in Passing HTML attributes to components.

Args:

  • attrs (dict, optional): Optional dictionary that holds HTML attributes. On conflict, overrides values in the default dictionary.
  • default (str, optional): Optional dictionary that holds HTML attributes. On conflict, is overriden with values in the attrs dictionary.
  • Any extra kwargs will be appended to the corresponding keys

The attributes in attrs and defaults are merged and resulting dict is rendered as HTML attributes (key="value").

Extra kwargs (key=value) are concatenated to existing keys. So if we have

attrs = {"class": "my-class"}
 

Then

{% html_attrs attrs class="extra-class" %}
 

will result in class="my-class extra-class".

Example:

<div {% html_attrs
     attrs
@@ -95,7 +95,7 @@
 

renders

<div class="my-class extra-class" data-id="123">
 

See more usage examples in HTML attributes.

provide¤

{% provide name: str, **kwargs: Any %}
 {% endprovide %}
-

See source code

The "provider" part of the provide / inject feature. Pass kwargs to this tag to define the provider's data. Any components defined within the {% provide %}..{% endprovide %} tags will be able to access this data with Component.inject().

This is similar to React's ContextProvider, or Vue's provide().

Args:

  • name (str, required): Provider name. This is the name you will then use in Component.inject().
  • **kwargs: Any extra kwargs will be passed as the provided data.

Example:

Provide the "user_data" in parent component:

@register("parent")
+

See source code

The "provider" part of the provide / inject feature. Pass kwargs to this tag to define the provider's data. Any components defined within the {% provide %}..{% endprovide %} tags will be able to access this data with Component.inject().

This is similar to React's ContextProvider, or Vue's provide().

Args:

  • name (str, required): Provider name. This is the name you will then use in Component.inject().
  • **kwargs: Any extra kwargs will be passed as the provided data.

Example:

Provide the "user_data" in parent component:

@register("parent")
 class Parent(Component):
     template = """
       <div>
@@ -126,7 +126,7 @@
 

❌ Don't do this

user = self.inject("user_data")["user"]
 

slot¤

{% slot name: str, **kwargs: Any [default] [required] %}
 {% endslot %}
-

See source code

Slot tag marks a place inside a component where content can be inserted from outside.

Learn more about using slots.

This is similar to slots as seen in Web components, Vue or React's children.

Args:

  • name (str, required): Registered name of the component to render
  • default: Optional flag. If there is a default slot, you can pass the component slot content without using the {% fill %} tag. See Default slot
  • required: Optional flag. Will raise an error if a slot is required but not given.
  • **kwargs: Any extra kwargs will be passed as the slot data.

Example:

@register("child")
+

See source code

Slot tag marks a place inside a component where content can be inserted from outside.

Learn more about using slots.

This is similar to slots as seen in Web components, Vue or React's children.

Args:

  • name (str, required): Registered name of the component to render
  • default: Optional flag. If there is a default slot, you can pass the component slot content without using the {% fill %} tag. See Default slot
  • required: Optional flag. Will raise an error if a slot is required but not given.
  • **kwargs: Any extra kwargs will be passed as the slot data.

Example:

@register("child")
 class Child(Component):
     template = """
       <div>
diff --git a/dev/reference/template_vars/index.html b/dev/reference/template_vars/index.html
index 2fe5ff82..0cbf16c6 100644
--- a/dev/reference/template_vars/index.html
+++ b/dev/reference/template_vars/index.html
@@ -1,5 +1,5 @@
  Template vars - Django-Components      

Template variables¤

Here is a list of all variables that are automatically available from inside the component's template and in on_render_before / on_render_after hooks.

is_filled instance-attribute ¤

is_filled: Dict[str, bool]
-

See source code

Dictonary describing which component slots are filled (True) or are not (False).

New in version 0.70

Use as {{ component_vars.is_filled }}

Example:

{# Render wrapping HTML only if the slot is defined #}
+

See source code

Dictonary describing which component slots are filled (True) or are not (False).

New in version 0.70

Use as {{ component_vars.is_filled }}

Example:

{# Render wrapping HTML only if the slot is defined #}
 {% if component_vars.is_filled.my_slot %}
     <div class="slot-wrapper">
         {% slot "my_slot" / %}
diff --git a/dev/sitemap.xml b/dev/sitemap.xml
index bbdb6b39..0613b618 100644
--- a/dev/sitemap.xml
+++ b/dev/sitemap.xml
@@ -2,214 +2,214 @@
 
     
          https://emilstenstrom.github.io/django-components/latest/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/SUMMARY/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/migrating_from_safer_staticfiles/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/release_notes/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/advanced/authoring_component_libraries/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/advanced/component_registry/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/advanced/hooks/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/advanced/html_tragments/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/advanced/provide_inject/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/advanced/rendering_js_css/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/advanced/tag_formatter/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/advanced/typing_and_validation/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/access_component_input/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/autodiscovery/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/component_context_scope/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/components_as_views/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/components_in_python/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/defining_js_css_html_files/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/html_attributes/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/single_file_components/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/slots/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/subclassing_components/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/concepts/fundamentals/template_tag_syntax/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/getting_started/adding_js_and_css/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/getting_started/adding_slots/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/getting_started/components_in_templates/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/getting_started/parametrising_components/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/getting_started/your_first_component/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/guides/devguides/dependency_mgmt/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/guides/devguides/slot_rendering/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/guides/devguides/slots_and_blocks/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/guides/setup/dev_server_setup/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/guides/setup/logging_and_debugging/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/guides/setup/syntax_highlight/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/overview/code_of_conduct/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/overview/community/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/overview/compatibility/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/overview/contributing/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/overview/development/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/overview/installation/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/overview/license/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/overview/security_notes/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/overview/welcome/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/reference/api/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/reference/commands/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/reference/components/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/reference/exceptions/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/reference/middlewares/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/reference/settings/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/reference/tag_formatters/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/reference/template_tags/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/reference/template_vars/
-         2025-01-14
+         2025-01-15
     
     
          https://emilstenstrom.github.io/django-components/latest/reference/urls/
-         2025-01-14
+         2025-01-15
     
 
\ No newline at end of file
diff --git a/dev/sitemap.xml.gz b/dev/sitemap.xml.gz
index 0ffeaee7..1b14a957 100644
Binary files a/dev/sitemap.xml.gz and b/dev/sitemap.xml.gz differ
diff --git a/versions.json b/versions.json
index f6c7b21a..316a7b3f 100644
--- a/versions.json
+++ b/versions.json
@@ -1,7 +1,7 @@
 [
   {
     "version": "dev",
-    "title": "dev (8cd4b03)",
+    "title": "dev (7ed4fd8)",
     "aliases": []
   },
   {