1

I tried to get layouts working following the docs and this example and I can't get layouts to work. I saw that in a github post that I needed to also install jstransformers (which I did) and the handlebars version as well.

The layout docs give an example of how to do it with the CLI but I can't see where I'm going wrong. I have tried a variety of options for layouts, including leaving them blank, but nothing seems to work.

Build.js

    var metalsmith = require('metalsmith');
    var markdown = require('metalsmith-markdown');
    var layouts = require('metalsmith-layouts');
    var handlebars = require('handlebars');
    var jstransformer = require('metalsmith-jstransformer');
    var handlebars = require('jstransformer')(require('jstransformer-handlebars'));

    metalsmith(__dirname)
      .metadata({
        site: {
          name: 'Electroniq',
          description: 'Test site with Metalsmith'
        }
      })
      .source('./src')
      .destination('./public')
      .clean(true)
      .use(markdown())
      .use(layouts({
        engine: 'handlebars',
        directory: './layouts',
        default: 'article.html',
        pattern: ["*/*/*html", "*/*html", "*html"]
       }))
      .build(function(err) {
        if (err) {
          console.log(err);
        } else {
          console.log('Site built!');
        }
      });

package.json

{
  "name": "electroniq",
  "version": "1.0.0",
  "private": true,
  "description": "Test blog with Metalsmith",
  "author": "GV",
  "dependencies": {
    "handlebars": "^4.0.11",
    "jstransformer-handlebars": "^1.1.0",
    "metalsmith": "^2.3.0",
    "metalsmith-collections": "^0.9.0",
    "metalsmith-jstransformer": "^0.13.2",
    "metalsmith-layouts": "^2.1.0",
    "metalsmith-markdown": "^0.2.2",
    "metalsmith-permalinks": "^0.5.0"
  },
  "main": "build.js",
  "scripts": {
    "prestart": "npm install",
    "start": "node ."
  }
}

Folder structure

-layouts
- -article.html
-node_modules
-public
-src
- -hello-universe.md
-build.js
-package.json
halfer
  • 19,824
  • 17
  • 99
  • 186
av0000
  • 1,917
  • 6
  • 31
  • 51

1 Answers1

1

Rename article.html to article.hbs and change the default layout accordingly.

Aankhen
  • 2,198
  • 11
  • 19
  • Layouts need to use an `.html` extension. – doublejosh Nov 10 '18 at 21:06
  • @doublejosh: I’m not sure where you read that, but please see [metalsmith-layouts](https://github.com/metalsmith/metalsmith-layouts) and the examples at https://metalsmith.io/ using a `layout.njk`. It’s not true that layouts need to use an extension of `.html`. – Aankhen Nov 12 '18 at 05:48
  • It's probably my `pattern` config. – doublejosh Dec 17 '18 at 21:42