Inheritance

2026-06-23

Everkm Publish supports a simple parent-child template structure. Blocks defined in the parent template can be inherited and overridden in child templates.

For example, parent template base.html:

<!DOCTYPE html>
<html lang="en">
<head>
    {% block head %}
    <link rel="stylesheet" href="style.css" />
    <title>{% block title %}{% endblock title %} - My Webpage</title>
    {% endblock head %}
</head>
<body>
    <div id="content">{% block content %}{% endblock content %}</div>
    <div id="footer">
        {% block footer %}
        &copy; Copyright 2008 by <a href="https://everkm.cn/">you</a>.
        {% endblock footer %}
    </div>
</body>
</html>

The above defines 4 blocks (head, title, content, footer). After inheriting in a child template, you can override specific blocks as needed.

Child template (inherits via extends) child.html:

{% extends "base.html" %}

{% block title %}Index{% endblock title %}

{% block head %}
    {{ super() }}
    <style type="text/css">
        .important { color: #336699; }
    </style>
{% endblock head %}

{% block content %}
    <h1>Index</h1>
    <p class="important">
      Welcome to my awesome homepage.
    </p>
{% endblock content %}

In a child template, using super() inside a block renders the parent template's block of the same name in that location. Below is a three-level template nesting example:

// grandparent.html
{% block hey %}hello{% endblock hey %}

// parent.html
{% extends "grandparent.html" %}
{% block hey %}hi and grandma says {{ super() }} {% block ending %}sincerely{% endblock ending %}{% endblock hey %}

// child.html
{% extends "parent.html" %}
{% block hey %}dad says {{ super() }}{% endblock hey %}
{% block ending %}{{ super() }} with love{% endblock ending %}

The rendered output of the above templates (excluding whitespace) is: "dad says hi and grandma says hello sincerely with love".

Blocks do not support externally newly assigned variables. For example:

Incorrect usage: x:, the output below will all cause errors.

{% set name="everkm" %}
{% set_global site="everkm.cn" %}

{% block header %}
{{name}}
{{site}}
{% endblock %}