ventojs / vento

🌬 A template engine for Deno & Node
https://vento.js.org/
MIT License
212 stars 12 forks source link

Feature request: "layouts" config option, similar to "includes" #67

Closed jvhellemond closed 5 months ago

jvhellemond commented 5 months ago

It would be great if there was a layouts config option to configure a directory where layouts can be found (if the path does not start with a "."), similar to the "includes" option for resolving include paths. Could that option be added?

oscarotero commented 5 months ago

include and layout are just two ways to import template files but the file loader doesn't know which tag originates the import.

But you can create your own loader with a different behavior. Take a look to the default file loader. It's just a class with two methods: load and resolve. You can create your own resolve logic, for example, if the path starts with layout:, search the files in a different directory.

export class MyLoader implements Loader {
  resolve(from: string, file: string): string {
    if (file.startsWith(".")) {
      // relative path
    }

    if (file.startsWith("layout:") {
      // look in the layouts folder
    }

    // look in includes folder.
  }
}
jvhellemond commented 5 months ago

Aha, thanks for the pointer. I like the idea of a path qualifier, like layout:. For now, I just put my template in the includes directory :)