#32324 closed Cleanup/optimization (fixed)
Wrapping the header in base.html of contrib.abmin in {% blocks %}. — at Version 5
Reported by: | Muskan Vaswan | Owned by: | Muskan Vaswan |
---|---|---|---|
Component: | contrib.admin | Version: | 3.1 |
Severity: | Normal | Keywords: | admin customize |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | yes |
Description (last modified by )
Use case
Allowing the user to overwrite the Top Navigation Bar od the admin page.
Existing method
to Overwrite the top nav-bar without having to overwrite the entire template of base.html, the user currently has to add the
{% extends "admin/base_site.html" %} {% load static %} {% block branding %} {% endblock %}
to admin/base_site.html and`
{% extends "admin/base.html" %} {% load static %} {% block usertools %} {% endblock %}
to admin/base.html.
No other method, other than overwriting the entire template exists.
Issue with Existing method
- Even after doing the above the top-bar doesn't entirely disappear dude to the CSS applied on the <div> with the id of header
(Image attached)
- The user must extend two separate files to even make this happen.
Solution
The simple solution is to wrap the entire header class using {% block ... %}. So the final django/admin/base.html would have:
<!-- Header --> {% block header %} <div id="header"> ... </div> {% endblock %} <!-- END Header -->
Final Result
The user will be able to overwrite the default blue-green nav-bar *entirely* by adding
{% extends "admin/base.html" %} {% load static %} {% block header %} {% endblock %}
to admin/base.html.
Change History (6)
comment:1 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
follow-up: 3 comment:2 by , 4 years ago
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
Summary: | Adding more blocks to the contrib.admin site → Adding more blocks to the contrib.admin site. |
comment:3 by , 4 years ago
That was an example... Also adding the entire header inside a block improves flexibility as it allows the user to change the entire topbar in one go rather changing singular elements. Not to mention currently if the user wants to make an entirely new topbar... ideally making the old one disappear entirely they would have to override and extend two files, that is, base_site.html for (branding block) and base.html (for the user_tools block) both and it still doesn't entirely dissapear. Which could simply be accomplished by adding a block for the entire header and the user could simply extend the base.html and {% block header %}{% endblock %}
.
Another example is if the user wants to change the add_url for a particular model having more blocks would be very helpful.
Replying to Mariusz Felisiak:
For example, the user can overwrite the entire navbar if the header was put inside {% block header %} simply by extending the template.
The navigation sidebar is already in a separate block
nav-sidebar
and use a separate template, so it's easy to customize, see comment. Also,header
already contains blocks for each element so I don't see how adding anotherblock
around existing blocks can increase flexibility.
comment:4 by , 4 years ago
Resolution: | invalid → needsinfo |
---|
Ticket described as "adding more blocks" cannot be accepted, it's too generic. You need to describe a concrete issue and use case. Maybe you should Set up your projects admin template directories for your use case.
Another example is if the user wants to change the add_url for a particular model having more blocks would be very helpful.
I don't think that templates are appropriate place for such logic.
comment:5 by , 4 years ago
Description: | modified (diff) |
---|---|
Summary: | Adding more blocks to the contrib.admin site. → Wrapping the header in base.html of contrib.abmin in {% blocks %}. |
In consideration of that, I wrote a more specific and comprehensive Issue. I hope this makes it more clear.
by , 4 years ago
Attachment: | Screen Shot 2021-01-06 at 5.02.36 PM.png added |
---|
The navigation sidebar is already in a separate block
nav-sidebar
and use a separate template, so it's easy to customize, see comment. Also,header
already contains blocks for each element so I don't see how adding anotherblock
around existing blocks can increase flexibility.