Thursday, April 25, 2013

Re: How can I divide a page into multiple parts using multiple html files and django templates?

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, bilgehan.balban@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+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.
>
>

--
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