Extends to be compatible with Include
So I am attempting to port some of my old python code that used Jinja2 and i noticed that I can not include something that extends something else. I don't understand why this would be? But lets say I have a card.html that contains blocks and then several other files that use this as a default template via extends Like Admin-info-card.html
if i were to load the page info.html which extends a base.html and attempt to include in a card extended component it will not due to includes not accepting extends.
{% extends 'base.htm' %}
{% from 'form_utils.htm' import render_field %}
{% block content %}
<form method="POST">
<div uk-grid>
<div class="uk-width-1-5">
{% include "components/admin-menu.html" %}
</div>
<div class="uk-width-expand">
{% include "components/admin-info-card.html" %}
</div>
</div>
</form>
{% endblock %}
the above is the info.html and below is the admin-info-card.html
{% extends "components/card.html" %}
{% block card %}
{% block card_title %}
Admin Information
{% endblock card_title %}
{% block card_body %}
<div uk-grid>
<div class="uk-width-1-2">
<span>Newest Member:</span>
<a href="{{ url_for('admin.user_edit', user_id=newest.id) }}">{{ newest.username }}</a>
</div>
<div class="uk-width-1-2"> <span>Total Users:</span> {{ users }} </div>
<div class="uk-width-1-2"> <span>Total Logs:</span> {{ logs }} </div>
</div>
{% endblock card_body %}
{% endblock card %}
Would it be possible to Extend the Extends to work in a way that would replace the current code with the extended bits before including it into the includes or at least have a limitation where you can only have 1 extends per document and the document being included cant contain the same extends as the document including it? Anyways this was a very common use pattern in Flask/jinja
Includes in Tera are a bit dumb. I pretty much never use them myself in both Tera and Jinja2 except for some very basic templates so I didn't bother implementing inheritance for them. Let's see if more people want that but I'm inclined to not support that.
yeah in a sense i was looking at how you did them and i would say you added them in the quickest possible way. XD However Rule of thumb is if you want more people to use Tera over other stuff then more features and support for things jinja and the rest have is a must. I might Attempt to fix the issue myself later on once i read into more on how you did things.
In practice you're the first person asking for it in 5 years so it might not be that common. Tera is not a re-implementation of Jinja in Rust, I wouldn't bother implementing it right now as I'm not sure I would merge it.
I do see what you mean. However most wont migrate to rust and will stay with Python till either Python devs no longer upkeep the libraries or until Rust has enough support for the things they need. I can manage around most issue's though so its fine if you add it or don't.
I'm trying to use Tera to build my own static site generator to use at work... I have a template file that has some lines roughly like this:
<!-- main.htm -->
<header>
<div class="container">
<ul class="nav">
{% block navbar_items %}
{% endblock navbar_items %}
</ul>
</div>
</header>
Then every language has its own folder and in each page I'd like to do:
{% extends "main.htm" %}
{% block navbar_items %}
{% include "_navbar.htm" %}
{% endblock navbar_items %}
{% block body %}
<h1>Hello, World!</h1>
<p>
The brown fox...
</p>
{% endblock body %}
In this way I can use the same base template, but I can override some shared blocks (like the navigation bar) for each language.
So this feature would be really useful...
It's still not going to happen in Tera v2
I've just spent a few hours debugging this wondering why it didn't work. I was assuming Tera would work similar to Jinja (especially as the extend says it's copied from the Jinja docs), and it didn't help that there was no error from Tera, nor an error from Zola about why it wasn't working. I can't see any reference to this limitation in the docs either.
Whether or not this feature should be supported, it would be awesome if an error was thrown explaining that it's not!