diff --git a/docs/concepts/advanced/authoring_component_libraries.md b/docs/concepts/advanced/authoring_component_libraries.md index 6fc9257e..f10693d7 100644 --- a/docs/concepts/advanced/authoring_component_libraries.md +++ b/docs/concepts/advanced/authoring_component_libraries.md @@ -1,6 +1,6 @@ --- title: Authoring component libraries -weight: 7 +weight: 8 --- You can publish and share your components for others to use. Here are the steps to do so: diff --git a/docs/concepts/advanced/component_registry.md b/docs/concepts/advanced/component_registry.md index da8c0c9c..be481912 100644 --- a/docs/concepts/advanced/component_registry.md +++ b/docs/concepts/advanced/component_registry.md @@ -1,6 +1,6 @@ --- title: Registering components -weight: 4 +weight: 5 --- In previous examples you could repeatedly see us using `@register()` to "register" diff --git a/docs/concepts/advanced/hooks.md b/docs/concepts/advanced/hooks.md index 9e0e47d2..13574763 100644 --- a/docs/concepts/advanced/hooks.md +++ b/docs/concepts/advanced/hooks.md @@ -1,6 +1,6 @@ --- title: Lifecycle hooks -weight: 3 +weight: 4 --- _New in version 0.96_ diff --git a/docs/concepts/advanced/html_tragments.md b/docs/concepts/advanced/html_tragments.md new file mode 100644 index 00000000..1b93c167 --- /dev/null +++ b/docs/concepts/advanced/html_tragments.md @@ -0,0 +1,361 @@ +--- +title: HTML fragments +weight: 2 +--- + +Django-components provides a seamless integration with HTML fragments ([HTML over the wire](https://hotwired.dev/)), +whether you're using HTMX, AlpineJS, or vanilla JavaScript. + +When you define a component that has extra JS or CSS, and you use django-components +to render the fragment, django-components will: + +- Automatically load the associated JS and CSS +- Ensure that JS is loaded and executed only once even if the fragment is inserted multiple times + +!!! info + + **What are HTML fragments and "HTML over the wire"?** + + It is one of the methods for updating the state in the browser UI upon user interaction. + + How it works is that: + + 1. User makes an action - clicks a button or submits a form + 2. The action causes a request to be made from the client to the server. + 3. Server processes the request (e.g. form submission), and responds with HTML + of some part of the UI (e.g. a new entry in a table). + 4. A library like HTMX, AlpineJS, or custom function inserts the new HTML into + the correct place. + +## Document and fragment types + +Components support two modes of rendering - As a "document" or as a "fragment". + +What's the difference? + +### Document mode + +Document mode assumes that the rendered components will be embedded into the HTML +of the initial page load. This means that: + +- The JS and CSS is embedded into the HTML as ` + +
+