layouts: Can't use partials or layouts unless they have .html extension

Hi all,

When I use this config

var layouts           = require('metalsmith-layouts')
Metalsmith(__dirname)
    .source('./src')
    .destination('./build')
    .use(permalinks())
    .use(inPlace({
        engine: 'handlebars',
        partials: './partials'
    }))
    .use(layouts({
        engine: 'handlebars',
        rename: true
    }))

I can happily use layout files in my layouts folder with .html extension. As soon as I rename those files to .hbs, I get this error Error: ENOENT: no such file or directory, open 'C:\Users\hi\Git\style-guide\layouts\datapoint.html' at Error (native)

I can continute to use the .html file extension for now, but any idea what I can do to use .hbs?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

I think I might understand this problem a bit, as I’m having it as well.

I’m trying to include {{> folder/foo }}

and in folder I have two files foo.config.yml foo.html

What I get is no such file or directory, open 'folder\foo.config.html'

It appears that the matching algorithm is a bit too loose and looks for anything foo.*, and finding foo.config.yml it tries to use it as an HTML file.


Few notes. If I remove foo.config.yml from the folder, it works fine. Also, I’ve tried using the pattern config pattern: **/*.html with no effect.

Yes, running gulp will compile the templates without errors since the default task is set up to use the metalsmith-in-place plugin (not metalsmith-layouts).

Ok, I missed that. Still, point 2 still stands.

There is definitely something wrong with the way metalsmith-layouts pulls in partials with the pattern option—it’s not filtering out files unmatched files.

We specifically test the pattern option. However, partials can be pulled in in a number of ways, so if there’s something wrong with it I’d be happy to take a look at it. But I’ll need a reduced test case, demonstrating the problem in a setup that is as minimal as possible. If you can reproduce the problem in that setting and have narrowed it down to a bug in metalsmith-layouts, then feel free to file it as a new issue and I’ll take a look at it.

Yes, running gulp will compile the templates without errors since the default task is set up to use the metalsmith-in-place plugin (not metalsmith-layouts).

This ^ is to illustrate that the pattern option works with the metalsmith-in-place plugin.

If you run gulp build:layouts, the task runner will attempt to compile the templates with metalsmith-layouts and will produce the stated error.

There is definitely something wrong with the way metalsmith-layouts pulls in partials with the pattern option—it’s not filtering out files unmatched files.

Ok. This is turning into troubleshooting your particular build config, which is not what the issues are for. If you’re running into problems with your particular config stack overflow is the place to ask for help. That way others with the same problem can find the solution as well.

The issues are meant for bugs for this particular library.

But, just to state what I found:

  1. I’ve cloned your repo, and for me the build works like it should. It includes the partial and throws no errors.
  2. I don’t think you understood what I meant with:

You’re misreading though. It’s trying to include: /Users/brains/development/testing/gulpsmith-layouts/source/partials/_footer.hbs and you have source/partials/footer.hbs

That error is correct. It doesn’t have anything to do with the scss partial. Read carefully.

If you find a bug in this library by all means report it, but this is not a bug in metalsmith-layouts. My advice would be to read the docs and not use gulp because you don’t need it for what you’re trying to do.