sidenav_base.html
<!-- basic side nav stuff -->
sidenav_specific.html
{% extends "sidenav_base.html" %}
<!-- specific side nav stuff -->
base.html
{% include "sidenav_specific.html" %}
Or if you're then extending base.html and want a different side nav, then put that last bit in a block:
{% block sidenav %}
{% include "sidenav_base.html" %}
{% endblock %}
And then in your subclass of base.html:
{% extends "base.html" %}
{% block sidenav %}
{% include "sidenav_specific.html" %}
{% endblock %}
_Nik
On 4/25/2013 5:13 PM, bilgehan.balban@gmail.com wrote:
Let us assume that I have 5 files like this that are included by base.html via "include". How would I then extend each of those? Looks like once you include a couple pages, you have no way of extending them each, because you have to render one child template.
Perhaps the best practice is to mix multiple views into one page, but I have no experience with django so I don't know.
Bahadir--
On Thursday, April 25, 2013 12:22:52 PM UTC-7, Nikolas Stevenson-Molnar wrote:The include would probably help you here:
https://docs.djangoproject.com/en/1.5/ref/templates/ builtins/#include
_Nik
On 4/25/2013 11:56 AM, bilgeha...@gmail.com wrote:
> Hi,
>
> I want to divide a page into parts, such as sidenav.html, topnav.html
> and so on such that the base.html is not cluttered with details of the
> complex topnav or sidebar. Problem is Django template inheritence can
> only have one to one parent child relationship and I cannot have
> multiple html child templateslike this. What would be the best way to
> go with this?
>
> Some of my examples:
>
> sidebar.html
> {% extends "base.html" %}
> {% block sidebar %{
> <!-- Lots of code about sidebar, unrelated to main page -->
> {% endblock %}
>
> head.html
> {% extends "base.html" %}
> {% block head %{
> <!-- Lots of code about html head tag, unrelated to main page -->
> {% endblock %}
>
> topnav.html
> {% extends "base.html" %}
> {% block topnav %{
> <!-- Lots of code about topnav, unrelated to main page -->
> {% endblock %}
>
>
> ... and base.html as simple as below:
> {% load staticfiles %}
> <html>
> {% block head %}{% endblock head %}
> <body>
> {% block topnav %}{% endblock topnav %}
> {% block container %}{% endblock container %}
> {% block sidebar %}{% endblock sidebar %}
> </body>
> </html>
>
> If what I am doing above is not best practice, what is the best
> practice to divide pages into concepts like this? This is just the
> beginning, essentially I want to insert more levels into this
> hierarchy, encapsulating details in different levels so that it is a
> maintainable program.
>
> Thanks,
> Bahadir
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en .
> For more options, visit https://groups.google.com/groups/opt_out .
>
>
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment