@@ -29,10 +29,14 @@ Module also working with [Grappelli Interface](https://github.com/sehmaschine/dj
2929- [ Special cases] ( #special-cases )
3030 - [ Complex Blocks] ( #complex-blocks )
3131 - [ Blocks without data in database. Only templates] ( #blocks-without-data-in-database-only-templates )
32+ - [ Add extra context to blocks] ( #add-extra-context-to-blocks )
3233 - [ Cache for reduce the number of database requests] ( #cache-for-reduce-the-number-of-database-requests )
3334- [ Settings] ( #settings )
3435
3536## Installation
37+
38+ Requirements: ` django>=3.* `
39+
3640` pip install django-streamfield `
3741
3842## How to use
@@ -150,6 +154,16 @@ you can get content by field cached property page.stream.render
150154...
151155```
152156
157+ Or, if you need extra context in blocks, you may use template tag:
158+ ```html
159+ {% load streamfield_tags % }
160+ ...
161+ < div class =" content" >
162+ {% stream_render page.stream request=request % }
163+ < / div>
164+ ...
165+ ```
166+
153167
154168# # Admin
155169# ## Custom admin class for block's models
@@ -268,6 +282,21 @@ class EmptyBlock(models.Model):
268282and use `streamblocks/ templates/ streamblocks/ emptyblock.html` for your content.
269283> Note: Don' t forget to register a block in STREAMBLOCKS_MODELS
270284
285+ # ## Add extra context to blocks
286+ Supose, you need to add some data to blocks from global context.
287+ Instead of using render property in template `{{ page.stream.render }}` ,
288+ you need to use template tag `stream_render` from `streamfield_tags` with keywords arguments.
289+
290+ For example, if you have in page template `request` and `page` objects and want to use it in blocks:
291+ ```html
292+ {% load streamfield_tags % }
293+ ...
294+ < div class = " content" >
295+ {% stream_render page.stream request=request page=page % }
296+ < / div>
297+ ...
298+ ```
299+
271300# ## Cache for reduce the number of database requests
272301There is two ways of caching:
273302- Simple cache view with django cache
0 commit comments