3

Basically what i want to accomplish is be able to access some variable or content from a template after performing extend then include.

No better way to explain what i want to do better than a sample code so,

  • home.html

    {% with page="homepage" %}
    {% extends "base.html" %}
    {% endwith %}
    
  • base.html

    {% include "sidebar.html" with origin=page %}
    
  • sidebar.html

    <h1>This is {{ origin }}'s sidebar</h1>
    

In the above example i want to end up with a header stating "This is homepage's sidebar"

Is there any built-in way to do so in Django? if not is there any non built-in solution?

Edit

I know it may seem that what i am trying to do can be accomplished by passing the data from within the view as template context. however that is not what i am trying to do, i want to set the variable or the content from within the template itself.

0 Answers0