[Fixed]-Django sekizai {% addtoblock %} tag is not working properly

29๐Ÿ‘

โœ…

{% addtoblock %} and {% endaddtoblock %} have to be inside of a block in templates that inherit another template.

# base.html
<html>
    ...
    {% render_block 'js' %}
    {% block js %}{% endblock %}
</html>


# some-page.html
{% inherits 'base.html' %}

{% block js %}
    {% addtoblock 'js' %}
        <script type="text/javascript" ... />
    {% endaddtoblock %}
{% endblock %}

Hope that helps you out.

๐Ÿ‘คBrandon Taylor

7๐Ÿ‘

{% addtoblock %} inside the template (something.html) from an inclusion tag:

from django import template
from django.conf import settings

register = template.Library()

@register.inclusion_tag('something.html', takes_context=True)
def render_something(context, some_arg):
    sezikai_ctx_var = getattr(settings, 'SEKIZAI_VARNAME', 'SEKIZAI_CONTENT_HOLDER')
    attrs = {
        'some_arg': some_arg,
        sezikai_ctx_var: context[sezikai_ctx_var]
    }
    return attrs
๐Ÿ‘คlaffuste

Leave a comment