I’ve got a site with a a number of applications, each one providing a section on the sidebar. Let’s say one app is “companies” providing company management (list, add, remove) and one is “employee”, allowing for employee management.
“companies” provides a section:
<div id="companies-sidebar">
<ul>
<li><a href="{% url 'company_add' %}">Add</a></li>
<li><a href="{% url 'company_remove' %}">Remove</a></li>
<li><a href="{% url 'company_list' %}">List</a></li>
</ul>
</div>
Same for the “employees”, with the employees_ URLs respectively.
I would like to order the two snippets in the sidebar section based on the application. If I’m in the view for e.g. company_list (or ..._remove or add), then the companies_sidebar snippet should be first. If I’m in the views corresponding to employees_..., then the employees_sidebar should be first.
The question is: How can I do it without flooding the templates with include-able snippets?
Some notes:
- I know this is not a normal UX pattern, where items change order.
- One solution would be to use custom (base.html?) templates for each app, with the changed items accordingly.
Write a custom template tag,
{% sidebar_snippets appname %}that takes the current app name as an argument. Then in the Python that implements sidebar_snippets, you can order the pieces any way you like.