Giter Club home page Giter Club logo

Comments (5)

ojii avatar ojii commented on May 19, 2024

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.

Eraldo avatar Eraldo commented on May 19, 2024

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.

ojii avatar ojii commented on May 19, 2024

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.

ojii avatar ojii commented on May 19, 2024

Closing this as my last comment should explain how to do this.

from django-sekizai.

Eraldo avatar Eraldo commented on May 19, 2024

Yes that explains it -- thank you @ojii. :)

from django-sekizai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.