Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template inheritance #54

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

alexbiehl
Copy link

@alexbiehl alexbiehl commented Aug 4, 2024

This PR adds the ability to extend templates via inheritance. Similar to what's available in Jinja.

Extending a template allows overriding "blocks" in the base template. This helps supporting more complex templating scenarios when developing web applications.

base.ede

<!doctype html>
{% block head %}
<title>{% block title %}{% endblock %}</title>
{% endblock %}
{% block body %}{% endblock %}

child.ede

{% extends "base.ede" %}
{% block title %}Index{% endblock %}
{% block head %}
  {{ super }}
  <style type="text/css">
    .important { color: #336699; }
  </style>
{% endblock %}
{% block body %}
  <h1>Index</h1>
  <p class="important">
    Welcome to my awesome homepage.
  </p>
{% endblock %}

Additionally,

  • there's a patch in here that introduces a "set" block that allows setting a variable to a template value.
  • with the notion of blocks it's very easy now to support rendering "template fragments" the HTMX way. Easy to add later.

If you are interested in these changes I can do refactoring if required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant