Skip to content

Commit 0212a54

Browse files
authored
feat: layer component (#1577)
1 parent 3ebc9c6 commit 0212a54

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

docs/components/layer.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Component - Layer
3+
order: 5
4+
description: Use the Layer component in Django Unfold as an abstract wrapper to inject variables from component classes into templates, enabling seamless data flow between Python logic and template rendering.
5+
---
6+
7+
# Layer component
8+
9+
The layer component functions as an abstract wrapper that encapsulates other components within the Unfold system. Its primary purpose is to provide a mechanism for injecting variables that are generated by component classes, enabling seamless data flow from your Python logic to the template rendering layer.
10+
11+
```python
12+
# admin.py
13+
14+
from unfold.components import register_component, BaseComponent
15+
16+
17+
@register_component
18+
class SomeComponent(BaseComponent):
19+
def get_context_data(self, **kwargs):
20+
context = super().get_context_data(**kwargs)
21+
context.update({
22+
"some_variable": [
23+
{
24+
"title": "Example A",
25+
},
26+
{
27+
"title": "Example B",
28+
}
29+
]
30+
})
31+
return context
32+
```
33+
34+
```html
35+
{% load unfold %}
36+
37+
{% component "unfold/components/layer.html" with component_class="SomeComponent" %}
38+
{% for item in some_variable %}
39+
{{ item.title }}
40+
{% endfor %}
41+
{% endcomponent %}
42+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ children }}

0 commit comments

Comments
 (0)