Zola - Include Template

06/26/2022, Sun
Categories: #cms

Common Template

Common content that belongs on multiple pages should be situated in a template which should be shared globally. An example of would be a footer, the bottom of the page content that persists across pages. Looking at Tera, the template engine for Zola, the include feature within a template offers the capability to reference other templates.

In other template languages, a shared template is also known as a partial.

Here is an index template that references a shared footer.html template on the bottom of the 'main' container:

<!DOCTYPE html>
<html lang="en">
    <head>
      ...
    </body>
        <div id="main">
            <div class="section footer">
                {% include "footer.html" %}
            </div>
        </div>
    </body>
</html>

Within the templates/footer.html file is the footer template:

<p>
    <span>
        Copyright © {{ now() | date(format="%Y") }} 
    Github.</a>
    </span>
</p>

The footer contains a copyright notice which uses the current year.