Skip to content

Template Blocks

A block is a named placeholder region that child templates can override.

diagram blocks are named holes, and naming them is the design mermaid
Every block in the base is a decision about what a page is allowed to change. Too few and children start duplicating the layout; too many and the base stops meaning anything. The common set is a title, a place for per-page styles, the main content, and a place for per-page scripts.
html
<!-- base.html -->
{% block content %}{% endblock %}
html
<!-- page.html -->
{% extends "base.html" %}
 
{% block content %}
  <h1>Page content</h1>
{% endblock %}

Base templates often have blocks like:

  • title
  • content
  • scripts
html
{% block scripts %}{% endblock %}

Child template:

html
{% block scripts %}
  <script src="{{ url_for('static', filename='app.js') }}"></script>
{% endblock %}

If you want to add to a parent block rather than replace it:

html
{% block scripts %}
  {{ super() }}
  <script src="{{ url_for('static', filename='extra.js') }}"></script>
{% endblock %}

That’s useful for base scripts shared across pages.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading