Inheritance

Everkm Publish supports a simple child-parent template structure. Block blocks are defined in the parent template and can be inherited and modified in the child template.

For example, the 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 %}
        {% block footer %}
        &copy; Copyright 2008 by <a href="https://everkm.com/">you</a>.
        {% endblock footer %}
    </div>
</body>
</html>

Above defines 4 blocks (head, title, content, footer), which can be overridden as needed when inherited in a sub-template.

Child template (inherited through 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> <p class="important">
{% endblock content %}

In child templates, the use of super() in a block means that the block of the same name from the parent template is rendered here. The following three levels of template nesting

// 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 above template renders the result (without whitespace) as "dad says hi and grandma says hello sincerely with love".

The block block does not support newly assigned external variables such as

Error Demonstration❌, the following output will all report errors.

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

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