liveBook · Manning

Content block

As explained in Coding with AI

A content block is a named region in a template that child content can fill or override.

A content block is a named region in a shared HTML template. Child templates fill that region while the surrounding structure—such as the title, header, and footer—stays reusable. section 7.3.2 section 7.2

Use a content block to:

  • Keep common page markup in one parent template instead of copying it into every page. section 7.3.2
  • Let each child template supply its own form, results, or other page-specific HTML. section 7.2
  • Connect templates through inheritance with {% extends ... %} and {% block content %}. section 7.2

A quiz page fills the content block

The parent template defines {% block content %}{% endblock %}. A child template extends the parent and places its question, answer choices, and submit button between {% block content %} and {% endblock %}. The same layout can then render a different results page without duplicating the outer HTML.

{% extends 'base.html' %}

{% block content %}
    <h1>{{ question[2] }}</h1>
    <form method="post">
        <input type="radio" name="answer" 
value="{{ question[3] }}">{{ question[3] }}</input><br>
        <input type="radio" name="answer" 
value="{{ question[4] }}">{{ question[4] }}</input><br>
        <input type="radio" name="answer" 
value="{{ question[5] }}">{{ question[5] }}</input><br>
        <input type="radio" name="answer" 
value="{{ question[6] }}">{{ question[6] }}</input><br>
        <input type="submit" value="Submit">
    </form>
{% endblock %}

Inspect a complete child template that inherits a parent and fills the content block with dynamic question data and a form. section 7.2

How Coding with AI covers it

How deep it goes
Explains the placeholder and inheritance pattern with working templates, but uses only basic Jinja2 features.
Examples
Uses shared index templates plus quiz and results pages containing forms, question data, and completion text.
What it assumes
Assumes basic HTML and Flask templates while introducing Jinja2 inheritance and dynamic template placeholders.
What you can do after
Apply it via Jinja2 inheritance to build Flask pages with reusable outer markup and replaceable page content.
How it connects
Connects template inheritance, Jinja2, Flask, dynamic content, and HTML forms.

This explainer was generated by Manning's knowledge graph from the text of Coding with AI. The section links point to the parts of the book it draws on.