templatetags ¤
component_tags ¤
component ¤
component(parser: Parser, token: Token, registry: ComponentRegistry, tag_name: str) -> ComponentNode
To give the component access to the template context
{% component "name" positional_arg keyword_arg=value ... %}
To render the component in an isolated context
{% component "name" positional_arg keyword_arg=value ... only %}
Positional and keyword arguments can be literals or template variables. The component name must be a single- or double-quotes string and must be either the first positional argument or, if there are no positional arguments, passed as 'name'.
Source code in src/django_components/templatetags/component_tags.py
component_css_dependencies ¤
component_css_dependencies(preload: str = '') -> SafeString
Marks location where CSS link tags should be rendered.
Source code in src/django_components/templatetags/component_tags.py
component_dependencies ¤
component_dependencies(preload: str = '') -> SafeString
Marks location where CSS link and JS script tags should be rendered.
Source code in src/django_components/templatetags/component_tags.py
component_js_dependencies ¤
component_js_dependencies(preload: str = '') -> SafeString
Marks location where JS script tags should be rendered.
Source code in src/django_components/templatetags/component_tags.py
fill ¤
fill(parser: Parser, token: Token) -> FillNode
Block tag whose contents 'fill' (are inserted into) an identically named 'slot'-block in the component template referred to by a parent component. It exists to make component nesting easier.
This tag is available only within a {% component %}..{% endcomponent %} block. Runtime checks should prohibit other usages.
Source code in src/django_components/templatetags/component_tags.py
html_attrs ¤
This tag takes: - Optional dictionary of attributes (attrs
) - Optional dictionary of defaults (defaults
) - Additional kwargs that are appended to the former two
The inputs are merged and resulting dict is rendered as HTML attributes (key="value"
).
Rules: 1. Both attrs
and defaults
can be passed as positional args or as kwargs 2. Both attrs
and defaults
are optional (can be omitted) 3. Both attrs
and defaults
are dictionaries, and we can define them the same way we define dictionaries for the component
tag. So either as attrs=attrs
or attrs:key=value
. 4. All other kwargs (key=value
) are appended and can be repeated.
Normal kwargs (key=value
) are concatenated to existing keys. So if e.g. key "class" is supplied with value "my-class", then adding class="extra-class"
will result in `class="my-class extra-class".
Example: