Skip to content

Commit 73eedf5

Browse files
authored
Merge pull request #324 from wrabit/update-template-partials-docs
add docs around django template partial support and comparison table
2 parents 6e1209a + a9739fb commit 73eedf5

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

README.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -632,23 +632,24 @@ Cotton is optimal when used with Django's cached.Loader. If you use <a href="htt
632632
633633
## Comparison with other packages
634634
635-
| **Feature** | **Cotton** | **django-components** | **Slippers** |
636-
|-----------------------------------------------------------------------------------------------------|----------------------------|----------------------------------------|------------------------------------------------------------|
637-
| **Intro** | UI-focused, expressive syntax | Holistic solution with backend logic | Enhances DTL for reusable components |
638-
| **Definition of ‘component’** | An HTML template | A backend class with template | An HTML template |
639-
| **Syntax Style** | HTML-like | Django Template Tags | Django Template Tags with custom tags |
640-
| **One-step package install** | ✅ | ❌ | ❌ |
641-
| **Create component in one step?** | ✅ <br> (place in folder) | ✅ <br> (Technically yes with single-file components) | ❌ <br> (need to register in YAML file or with function) |
642-
| **Slots** <br> Pass HTML content between tags | ✅ | ✅ | ✅ |
643-
| **Named Slots** <br> Designate a slot in the component template | ✅ | ✅ | ✅ (using ‘fragments’) |
644-
| **Dynamic Components** <br> Dynamically render components based on a variable or expression | ✅ | ✅ | ❌ |
645-
| **Scoped Slots** <br> Reference component context in parent template | ❌ | ✅ | ❌ |
646-
| **Dynamic Attributes** <br> Pass string literals of basic Python types | ✅ | ❌ | ❌ |
647-
| **Boolean Attributes** <br> Pass valueless attributes as True | ✅ | ✅ | ❌ |
648-
| **Implicit Attribute Passing** <br> Pass all defined attributes to an element | ✅ | ❌ | ✅ |
649-
| **Django Template Expressions in Attribute Values** <br> Use template expressions in attribute values | ✅ | ❌ | ❌ |
650-
| **Attribute Merging** <br> Replace existing attributes with component attributes | ✅ | ✅ | ❌ |
651-
| **Multi-line Component Tags** <br> Write component tags over multiple lines | ✅ | ✅ | ❌ |
635+
| **Feature** | **Cotton** | **django-components** | **Slippers** | **Template Partials** |
636+
|-----------------------------------------------------------------------------------------------------|----------------------------|----------------------------------------|------------------------------------------------------------|-----------------------------------------------------------|
637+
| **Intro** | UI-focused, expressive syntax | Holistic solution with backend logic | Enhances DTL for reusable components | Inline named partials for HTMX |
638+
| **Definition of 'component'** | An HTML template | A backend class with template | An HTML template | A named fragment within a template |
639+
| **Syntax Style** | HTML-like | Django Template Tags | Django Template Tags with custom tags | Django Template Tags |
640+
| **One-step package install** | ✅ | ❌ | ❌ | ✅ <br> (built-in since Django 6.0) |
641+
| **Create component in one step?** | ✅ <br> (place in folder) | ✅ <br> (Technically yes with single-file components) | ❌ <br> (need to register in YAML file or with function) | ✅ <br> (define with `{% partialdef %}`) |
642+
| **Renderable from views** <br> Render a component directly from a Python view | ✅ | ✅ | ❌ | ✅ <br> (via `template#partial` syntax) |
643+
| **Slots** <br> Pass HTML content between tags | ✅ | ✅ | ✅ | ❌ |
644+
| **Named Slots** <br> Designate a slot in the component template | ✅ | ✅ | ✅ (using 'fragments') | ❌ |
645+
| **Dynamic Components** <br> Dynamically render components based on a variable or expression | ✅ | ✅ | ❌ | ❌ |
646+
| **Scoped Slots** <br> Reference component context in parent template | ❌ | ✅ | ❌ | ❌ |
647+
| **Dynamic Attributes** <br> Pass string literals of basic Python types | ✅ | ❌ | ❌ | ❌ |
648+
| **Boolean Attributes** <br> Pass valueless attributes as True | ✅ | ✅ | ❌ | ❌ |
649+
| **Implicit Attribute Passing** <br> Pass all defined attributes to an element | ✅ | ❌ | ✅ | ❌ |
650+
| **Django Template Expressions in Attribute Values** <br> Use template expressions in attribute values | ✅ | ❌ | ❌ | ❌ |
651+
| **Attribute Merging** <br> Replace existing attributes with component attributes | ✅ | ✅ | ❌ | ❌ |
652+
| **Multi-line Component Tags** <br> Write component tags over multiple lines | ✅ | ✅ | ❌ | ❌ |
652653
653654
**Notes:**
654655

docs/docs_project/docs_project/templates/django_template_partials.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<c-layouts.with-sidebar>
22
<h1>Setting up Cotton with Django Template Partials</h1>
33

4+
<c-note>
5+
<strong>Django 6.0+:</strong> Template partials are now built into Django core. The instructions below are only needed if you're using the <code>django-template-partials</code> package on Django &lt; 6.0. For Django 6.0+, no additional configuration is required to use partials alongside Cotton.
6+
</c-note>
7+
48
<p>Both packages come with an auto-setup feature, but to get the packages working together we need to opt instead
59
for the corresponding 'SimpleAppConfig' from each package:</p>
610

0 commit comments

Comments
 (0)