Closed jvhellemond closed 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.
}
}
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 :)
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?