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 7869559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:21:42+00:00 2026-06-03T01:21:42+00:00

When I blog, I like to separate each blog-post into its own .html file

  • 0

When I blog, I like to separate each blog-post into its own .html file (is that ok?)

This prevents the file getting too big, and makes it easy to go back and edit a previously written blog post if need be.

Occasionally the blog post will contain css/js/ajax/template variables.

But on my website, I like all the blog posts on one page (so I can scroll through them all, instead of going to a separate page for each post)

Here is an html file that contains two blog posts:

{% extends "base.html" %}
{% block blog_posts %}
    <!-- links/targest for the side menu to jump to a post -->
    <li><a href="#post2">Post2 - April 2012</a></li>
    <li><a href="#post1">Post1 - Feb 2012</a></li>
{% endblock %}

{% block content %}

<div id="post1">
spam1 blah blah
</div>

<div id="post2">
spam2
</div>
{% endblock %}

and in base.html I have something like:

<div id="content-container">
        <div id="section-navigation">
            <ul>
                {% block blog_posts %}
                {% endblock %}
            </ul>
        </div>
        <div id="content">
            {% block content %}{% endblock %}
        </div>
</div>

What is the best way for me to split these blog posts out into separate files using webapp2 and jinja2?

e.g. blog1.html might look like:

{% block blog_posts %}
        <!-- links/targest for the side menu to jump to a post -->
        <li><a href="#post1">Post1 - Feb 2012</a></li>
    {% endblock %}

{% block content %}

    <div id="post1">
    spam1 blah blah
    </div>
{% endblock %}

(And I would want the links and the blogposts to be displayed in the right order on the website)

I could think of a way of doing it where post2 extends post1.html, post3 extends post2.html etc, but I would prefer to fan out more

“Henry and Kafura introduced Software Structure Metrics Based on Information Flow in 1981[2] which measures complexity as a function of fan in and fan out.”

Thanks

  • 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-03T01:21:44+00:00Added an answer on June 3, 2026 at 1:21 am

    @robert king, your design has data embedded directly in the template. Templates should only contain the blueprint to a view, and they should be rendered with new data generated from your main code every time. I simulate this process here (Edited to illustrate the use of a loop to extract post titles, and the display of a single post.):

    import jinja2
    
    # NOTE: in this template there is no data relating to specific posts.
    # There are only references to data structures passed in from your main code
    page_template = jinja2.Template('''
        <!-- this is a navigation block that should probably be in base.html -->
        {% block blog_posts %}
            <!-- links/targets for the side menu to jump to a post -->
            {% for post in posts %}
              <li><a href="{{ post.url }}">{{ post.title }} 
                                           - {{ post.date }}</a></li>
            {% endfor %}
        {% endblock %}
    
        <!-- this is a content block that should probably be in page.html -->
        {% block content %}
            <div id="post">
                <h1>{{ current.title }}</h1>
                <h2>{{ current.date }}</h2>
                <p>{{ current.content }}</p>
            </div>
        {% endblock %}
    ''')
    
    # NOTE your main code would create a data structure such as this 
    # list of dictionaries ready to pass in to your template
    list_of_posts = [
             { 'url' : '#post1',
              'title' : 'My first post',
              'date' : 'Feb 2012',
              'content' : 'My first post is about Hello World.'},
    
             { 'url' : '#post2',
              'title' : 'My second post',
              'date' : 'Apr 2012',
              'content' : 'My second post is about Foo Bar.'}
             ]
    
    # Pass in a full list of posts and a variable containing the last
    # post in the list, assumed to be the most recent. 
    print page_template.render(posts = list_of_posts,
                               current = list_of_posts[-1])
    

    Hope this helps.

    EDIT See also my answer to a question on “Site fragments – composite views”

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

Sidebar

Related Questions

I'm working on this application that's sort of like a blog. I'm thinking about
like in this post here by exemple I have found this blog but in
Each Pyramid application has an associated .ini file that contains its settings. For example,
I have a blog-style app that allows users to tag each post with topics.
I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/ Now i want to
I've been working on my own django based blog (like everyone, I know) to
I am developing android web application for a blog like website. For this I
I'd like to reveal only post titles on my blog posts loop, and when
I would like to create a front page for a Wordpress blog that contains
Is it possible to include inline assembly in Go code? This blog post shows

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.