You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 15, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+12-12Lines changed: 12 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -23,19 +23,19 @@ Extending the Django template system so that you can include a view inside anoth
23
23
24
24
Django View Composer is released on PyPi so you can install using Pip:
25
25
26
-
```
26
+
```sh
27
27
pip install django-view-composer
28
28
```
29
29
30
30
or Poetry:
31
31
32
-
```
32
+
```sh
33
33
poetry install django-view-composer
34
34
```
35
35
36
36
Once installed, add to your `INSTALLED_APPS` setting to register the template tags:
37
37
38
-
```
38
+
```python
39
39
INSTALLED_APPS= [
40
40
...
41
41
"django_view_composer",
@@ -49,15 +49,15 @@ The `{% view %}` tag renders a class based view and includes the content in the
49
49
50
50
It has 1 required argument which is the import string for the view:
51
51
52
-
```
52
+
```html+django
53
53
{% load view_composer %}
54
54
55
55
{% view 'myapp.views.MyView' %}
56
56
```
57
57
58
58
You can also provide a variable for the import string which will be resolved from the current template's context:
59
59
60
-
```
60
+
```html+django
61
61
{% view view_to_render %}
62
62
```
63
63
@@ -71,21 +71,21 @@ If any context variable names conflict, whatever the child view sets in it's own
71
71
72
72
You can pass additional context from the template tag:
73
73
74
-
```
74
+
```html+django
75
75
{% view 'myapp.views.MyView' with foo='bar' %}
76
76
```
77
77
78
78
Additional variables can be resolved from the current template's context to pass to the included view:
79
79
80
-
```
80
+
```html+django
81
81
{% view 'myapp.views.MyView' with foo=foo %}
82
82
```
83
83
84
84
### Use `only` to limit context
85
85
86
86
If you want to render the included view only with the variables provided (or even no variables at all), use the only option. No other variables will be provided to the included view.
87
87
88
-
```
88
+
```html+django
89
89
{% view 'myapp.views.MyView' with foo='bar' only %}
90
90
```
91
91
@@ -95,7 +95,7 @@ The `{% viewblock %}` tag renders a class based view and includes the content in
95
95
96
96
This tag must be closed with a corresponding endviewblock. It has 1 required argument which is the import string for the view:
97
97
98
-
```
98
+
```html+django
99
99
{% load view_composer %}
100
100
101
101
{% viewblock 'myapp.views.MyView' %}
@@ -105,7 +105,7 @@ This tag must be closed with a corresponding endviewblock. It has 1 required arg
105
105
106
106
In the template for the `myapp.views.MyView`, you can use the children context variable to decide where to render the block content:
107
107
108
-
```
108
+
```html+django
109
109
<div>
110
110
{{ children }}
111
111
</div>
@@ -140,7 +140,7 @@ If you need to handle a different method in an included view, such as a child vi
0 commit comments