directory = metalsmith's base folder
directory / test.txt = a file to render, but with no frontmatter
directory / layouts / layout.txt = so the default layout template
directory / layouts / specific / layout.txt = some specific template
directory / partials / partial.text = a partial with whatever content
both layout.txt files have the following content: partial: [{{>partial}}]
test.txthas the following content: whatever (i.e. no frontmatter at all)
Test 1
At first, (index.js / render / line 149) will be executed with str representing an absolute path to the current template file. And str will be passed on as path to (consolidate.js / readPartials / line 121), which it will use in var file = join(dirname(path), partials[key] + extname(path));
In short: consolidate.js recreates an absolute path to the partial file by using the template file's extension, which will fail (.txt vs .text) if it tires to read the partial's contents.
Now I realize, that consolidate is responsible for this quirk, but it might help, if the metalsmith-layouts' documentation would mention that template files and partial files must use the same file extension.
Test 2
Alright, lets rename "partial.text" to partial.txt.
This will work just fine.
Test 3
Now, lets change the content of directory / test.txt to:
---
layout: specific/layout.txt
---
whatever
This will fail because (read-partials.js / readPartials / line 37) calculates a path to the partial file that is relative to the base layout folder (see options.directory) and because consolidate.js uses the layout file's actual folder (see above). Both folders don't have to match!
Now that you already seem to work on version 2, please document that if you are using partials, then all template files must be located inside the options.directory folder and not in any subfolder.
In the hopes that this will help anyone ...
Lets assume the following:
layout.txt
files have the following content:partial: [{{>partial}}]
test.txt
has the following content:whatever
(i.e. no frontmatter at all)Test 1
At first, (index.js / render / line 149) will be executed with
str
representing an absolute path to the current template file. Andstr
will be passed on aspath
to (consolidate.js / readPartials / line 121), which it will use invar file = join(dirname(path), partials[key] + extname(path));
In short: consolidate.js recreates an absolute path to the partial file by using the template file's extension, which will fail (
.txt
vs.text
) if it tires to read the partial's contents.Now I realize, that consolidate is responsible for this quirk, but it might help, if the metalsmith-layouts' documentation would mention that template files and partial files must use the same file extension.
Test 2
Alright, lets rename "partial.text" to
partial.txt
.This will work just fine.
Test 3
Now, lets change the content of
directory / test.txt
to:This will fail because (read-partials.js / readPartials / line 37) calculates a path to the partial file that is relative to the base layout folder (see options.directory) and because consolidate.js uses the layout file's actual folder (see above). Both folders don't have to match!
Now that you already seem to work on version 2, please document that if you are using partials, then all template files must be located inside the
options.directory
folder and not in any subfolder.