Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8056497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:43:20+00:00 2026-06-05T08:43:20+00:00

Yo so i have a base.html: <html> <body> <div id=header> … </div> {% block

  • 0

Yo

so i have a base.html:

<html>
    <body>
        <div id="header"> ... </div>
        {% block main %}{% endblock %}
        <div id="footer"> ... </div>
    </body>
</html>

and i also have a page that shows user’s posts:

{% extends base.html %|
{% block main%}
    <h1>welcome to yours posts hangout!</h1>

      ... snazzy code here that shows all the posts ...

{% endblock%}

now, the problem is, maybe i have another page like this:

{% extends base.html %|
{% block main%}
    <h1>look at all posts by all users!</h1>

      ... snazzy code here that shows all the posts by all the users ...

{% endblock%}

because we all belong to mensa, we can see that the snazzy code i have is being repeated – twice (for tautological fun!)

i don’t want to repeat this code – i mean, if it is going to be a major hassle i will, but otherwise i’d like the one page that has the snazzy code defined, and then slip the small changes above and (possibly) below it in.

my understanding of templates is shaky though – i think this is the way to go about doing it, is there a better/standardised way?

snazzy.html:

{% extends base.html %|
  {% block aboveSnazzy%}
  {% endblock %}

      ... snazzy code here that shows all the posts by all the users ...

  {% block belowSnazzy%}
  {% endblock %}
{% endblock%}

and then for each of the different pieces, i can have:

usersArea.html:

{% extends snazzy.html %|
  {% block aboveSnazzy%}
      <h1>welcome to yours posts hangout!</h1>
  {% endblock %}


  {% block belowSnazzy%}
      <h1>i didn't think this far ahead in the example</h1>
  {% endblock %}
{% endblock%}

etc etc for the other pieces too!

ok, so i know i can just send in a parameter with a different header or what have you – let’s pretend that the aboveSnazzy stuff is, i don’t know, showing some other template i’d like or doing something non-trivial. Is what i’ve detailed above the “way” to do it?

cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:43:23+00:00Added an answer on June 5, 2026 at 8:43 am

    Yo. 🙂

    The answer depends on how much your templates have in common.

    • If your templates do have much in common, i.e. they are pages of some section of your site, or just have a very common structure, then your way of doing it would be correct. I just think that you should use more descriptive names for the blocks.

      {% extends base.html %}
      {% block page_heading %}{% endblock %}
          ... snazzy code here that shows all the posts by all the users ...
      {% block extra_content %}{% endblock %}
      
    • If your templates don’t have much in common, but share some specific block of content, then it’s a different situation since it’s difficult to make a properly inherited structure. You should use the {% include %} tag in this case. For example, make another template that shows posts, say _list_posts.html, then use it in the children templates.

      {% extends base.html %}
      {% block main %}
      <h1>Welcome to your posts hangout!</h1>
      {% include '_list_posts.html' %}
      {% endblock %}
      

      You could also use the inclusion tag for that.

    So, which option should you choose? Try to answer the question: should these two templates have a common parent? If yes, go for the first option. Otherwise, go for the second option.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base layout, BaseLayout.cshtml: <html> <body> @RenderBody() <div id=footer> @if (!IsSectionDefined(Footer)) {
I have a base.html template that contains a list of links. Example: <div id=sidebar1>
I have a file called header.html and it is included by base.html . In
I have an aspx page which shows preview of html-email. The html email comes
I have the following HTML (excerpt from larger code-base) <div class=diary-event ui-corner-all title=[title]> <span
I have a BasePage.java (together with a BasePage.html ). My base page is basically
This is my base.html <!DOCTYPE html> <head> <title> My Site </title> </head> <body> <div
i have template base.html and some children templates. I don't know how to set
I have a base.html which has a login section at the top of every
I have a ListView. If I want to base the html markup on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.