Templates: Usage of an 'extends' function

I have a working prototype of an extends function for templates. I wanted to get some feedback on the implementation though…

{{ extends "path/to/parent/template"}}

Because extends necessarily works “bottom up”, it has to be pre-processed before execution. This means that every template has to be checked. I think there are two ways to check, and not sure what the community thinks would be best (if this should be added at all):

  1. extends can only be the first node
    Less costly, only check the first line of any given template. Means you can’t have extends and frontmatter.
  2. extends can be in an arbitrary place
    Have to check every node of a template for extends. Somewhat costly if you have a lot of nodes

My goal with the code is to add the least amount of cost to templates that don’t have an extends block, but weighing that against use-cases

Thoughts?

1 Like

Another option…it could be in the first N nodes, allowing you to have front matter with templated data, but only a finite amount

---
title: "title"
---
{{ extends "base.html" }}

extends is node[1]

---
title: {{ $somevar }}
---
{{ extends "base.html" }}

extends is node[3]

{{ extends "base.html" }}
---
title: "title"
---

extends is node[0], breaks front matter splitter…OR modify that to ignore an extends node?

So many options!

This topic was automatically closed after 60 days. New replies are no longer allowed.