Comments (5)
I'm not sure I understand what you're trying to do.
Is this what you're doing (semi-pseudocode)?
def foo():
context1 = SekizaiContext()
output = render_to_string('template1.html', context1)
context2 = SekizaiContext({
'output': output
})
return render_to_string('tempalte2.html', context2)
{# template1.html #}
{% addtoblock "css" %}hoge{% endaddtoblock %}
{# template2.html #}
{% render_block "css" %}
{{ output|safe }}
from django-sekizai.
Close..
Difference: Imagine that foo being a template tag that does only use (render) template1
.
Example:
@register.simple_tag(takes_context=True)
def label(context, label=None, **kwargs):
label = label or context.get('label', {})
label_context = label
label_context.update(kwargs)
label_template = 'atoms/label.html'
return render_to_string(label_template, context=label_context)
So.. the difference is that label (template tag) only renders its template.
And I call the template tag in my main template somewhere.
The mein sekizai block tags are in the main template.
Does it make sense now?
from django-sekizai.
sekizai cannot work if you isolate the context. You can however manually pass it:
from sekizai.helpers import get_varname
@register.simple_tag(takes_context=True)
def label(context, label=None, **kwargs):
label = label or context.get('label', {})
label_context = label
label_context.update(kwargs)
label_context[get_varname()] = context[get_varname()] # inherit sekizai context
label_template = 'atoms/label.html'
return render_to_string(label_template, context=label_context)
from django-sekizai.
Closing this as my last comment should explain how to do this.
from django-sekizai.
Yes that explains it -- thank you @ojii. :)
from django-sekizai.
Related Issues (20)
- Documentation on readthedocs is out of date HOT 2
- Add support for Django 3.2 HOT 4
- Error when adding Sekizai HOT 1
- 3.0.0: Tests missing in sdist tarball on pypi.org HOT 4
- The use of setup.py test is deprecated HOT 1
- RTD maintenance HOT 2
- helpers._scan_namespaces silently gives up when encountering a with_data node (SekizaiParser dropping template nodes?) HOT 13
- Code alerts by lgtm HOT 1
- Django 4.2 support? HOT 2
- Is it possible to detect an empty block?
- Missing tag for 1.0.0 release HOT 2
- pep8 dependency should be replaced by pycodestyle HOT 1
- Use flake8 instead of pep8 HOT 1
- tests missing from pypi sdist HOT 3
- Can`t use render_to_string without a given request HOT 1
- Django 3.1 compatibility HOT 2
- Remove compatibility import of Context in django.template.base HOT 1
- Import Error with Django 3.1 HOT 1
- 2.0.0 installs tests top-level HOT 1
- sekizai tag addtoblock silently ignored HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-sekizai.