[Fixed]-Django template reusability

1πŸ‘

βœ…

In this case, I could consider a template of header only:

# header-template.html

<header>
    <div class="pull-left">
      <h2><i class="fa {{ icon }}"></i>
        {{ title }}
      </h2>
    </div>
    <div class="pull-right">
      <a class="btn btn-default btn-sm toggle-widget" href="#">
        <i class="fa fa-minus"></i>
      </a>
    </div>
</header>

and, then use it in widgets:

<div class="widget">
  {% include "header-template.html" with icon="1" title="user-info" %}
  <div class="inner-padding">
    .............
  </div>
</div>


<div class="widget">
  {% include "header-template.html" with icon="2" title="product-list" %}
  <div class="inner-padding">
    .............
  </div>
</div>

If you think that for some of the widgets the content is also common, then you can create a template of that too, and use it in the widget.

πŸ‘€AKS

Leave a comment