-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
render_to_string #61
Comments
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 }} |
Close.. 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. Does it make sense now? |
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) |
Closing this as my last comment should explain how to do this. |
Yes that explains it -- thank you @ojii. :) |
How can I add css to my header when rendering something to a string that later gets displayed on a template that inherits from base.
Here it would make sense that only at then end when the base template is rendered it also grabs all addtoblock elements and pulls them into the header or something like that.
What do you think? Or do you have alternative ideas on how to handle it?
The text was updated successfully, but these errors were encountered: