Template Tags¶
Module Summary¶
The framework registers its template tags as Django builtins through next.apps.templates.install.
Templates therefore use them without an explicit {% load %} statement.
Forms¶
- {% form @action="<name>" %}...{% endform %}
Renders a form bound to a registered action. Injects the CSRF token and the hidden
_next_form_pageorigin field. The block body has access to the bound or unbound form through{{ form }}.The HTTP method is always
post. It cannot be passed as an argument.Accepts every HTML attribute as a keyword. Captured URL parameters from
request.resolver_match.kwargsare emitted automatically as_url_param_<name>hidden inputs. They are not passed as tag arguments.The tag requires
requestandcurrent_page_module_pathin the template context. The file router supplies both, so{% form %}works only inside a file-routed page.
Components¶
- {% component "<name>" key="value" ... %}
Void form. Renders a component by name with the given literal string props.
- {% #component "<name>" %}...{% /component %}
Block form. Renders a component and substitutes child content through slots.
- {% slot "<name>" %}
Void form. Fills a named slot from the caller inside a
{% #component %}block.
- {% #slot "<name>" %}...{% /slot %}
Block form. Fills a named slot with body content from the caller inside a
{% #component %}block.
- {% set_slot "<name>" %}
Void form. Marks a slot location inside a component template, with no default body.
- {% #set_slot "<name>" %}...{% /set_slot %}
Block form. Marks a slot location inside a component template, with a fallback body used when the caller omits the slot.
Multiline tag bodies¶
The framework reinstalls Django’s template tag pattern with the re.DOTALL flag so a single {% ... %} token may span several lines.
That allows readable block components and slots when the inner markup is long.
Caution
This changes template parsing for every template the process loads, not only DJX files.
If you rely on Django’s stock behaviour where a newline inside {% ... %} ends the tag, adjust those templates before adopting next.dj.
Static Pipeline¶
- {% collect_styles %}
Marks the placeholder slot where collected CSS link tags are injected. Takes no arguments.
- {% collect_scripts %}
Marks the placeholder slot where collected JS and module tags are injected. Takes no arguments.
- {% use_style "<url>" %}
Registers an external CSS URL on the active collector. The asset is prepended so shared dependencies load before co-located styles.
- {% use_script "<url>" %}
Registers an external JS URL on the active collector. The asset is prepended the same way as
use_style.
- {% #use_style %}...{% /use_style %}
Inline CSS block. The body is rendered with the template context and deduplicated by content.
- {% #use_script %}...{% /use_script %}
Inline JS block. The body is rendered with the template context and deduplicated by content.
Layouts¶
- {% block template %}{% endblock %}
Marks the slot inside a
layout.djxwhere the page template is composed. The layout loader replaces the empty block with the wrapped page body when it builds the final template string. Both{% endblock %}and{% endblock template %}are accepted as the closing tag.A
layout.djxwithout this block raisesnext.W001duringmanage.py check, since the page body would have nowhere to render. Nested layouts each carry their own{% block template %}and compose from innermost to outermost.
Tag Loading¶
- next.apps.templates.install() → None[source]
Add next-dj templatetag modules to TEMPLATES[0].OPTIONS.builtins.
The framework calls install during AppConfig.ready.
Project code does not need to load the tag libraries manually.
See Also¶
See also
Form Templates for the {% form %} tag.
Components for {% component %} and slots.
Static Template Tags for the static tags.