django-template-partials¶
Reusable named inline partials for the Django Template Language.
Installation¶
Using the auto settings of django-template-partials will conflict with dj-angles. You will need to install it using the advanced configuration.
# settings.py
INSTALLED_APPS = {
...
"template_partials.apps.SimpleAppConfig",
...
}
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"OPTIONS": {
"context_processors": [
...
],
"loaders": [
(
"template_partials.loader.Loader",
[
(
"django.template.loaders.cached.Loader",
[
"dj_angles.template_loader.Loader",
"django.template.loaders.filesystem.Loader",
"django.template.loaders.app_directories.Loader",
],
)
],
)
],
"builtins": [
...
"template_partials.templatetags.partials",
...
],
},
},
]
Define a partial¶
Define a template partial.
<dj-partial name="test-partial">
TEST-PARTIAL-CONTENT
</dj-partial>
is equivalent to:
{% partialdef test-partial %}
TEST-PARTIAL-CONTENT
{% endpartialdef %}
Use a partial¶
Render a defined template partial.
<dj-partial name="test-partial" />
is equivalent to:
{% partial test-partial %}
Define an inline partial¶
Defines a template partial and renders it in-place.
<dj-partial name="test-partial" inline>
TEST-PARTIAL-CONTENT
</dj-partial>
is equivalent to:
{% partialdef test-partial inline %}
TEST-PARTIAL-CONTENT
{% endpartialdef %}