Closed mischah closed 7 years ago
Is this a bug or on purpose?
That's on purpose, the tutorial is incorrect. You can use metalsmith-in-place for rendering content in content pages (version 1 uses consolidate (like metalsmith-layouts), version 2 uses jstransformers).
Thanks for the quick reply.
One additional question. Am I wright that it is a decision between metalsmith-in-place
and metalsmith-layouts
?
Because I would love to be able to use partials in content pages as well as in layout files ๐
Am I wright that it is a decision between metalsmith-in-place and metalsmith-layouts?
You can use both at the same time. You can also use them both multiple times with different settings. So it's all possible ๐
Okay. I donโt get it to work over here. Trying for about 2 hours for now ๐
Do I have to run metalsmith two times with different sources destinations to accomplish that?
Like first using metalsmith-in-place
to render the content pages than using metalsmith-layouts
to combine the rendered content pages with the layout?
Or can I chain them within one build?
Just chain them in one build. Also try stack overflow and the slack channel for help.
Thanks. Appreciate your time ๐
I got it up and running ๐
Just leaving a note for people who might stumble about that :octocat:
Itโs actually easier that I thought to accomplish that. Here is my complete build file:
const metalsmith = require('metalsmith');
const layouts = require('metalsmith-layouts');
const inPlace = require('metalsmith-in-place');
const registerHelpers = require('metalsmith-register-helpers');
metalsmith(__dirname)
.source('../src')
.destination('../build')
.clean(true) // Clean destination before build
.use(registerHelpers({
directory: '../src/handlebars/helpers'
}))
.use(layouts({ // Wrap layouts around content pages
engine: 'handlebars',
rename: false,
directory: '../src/handlebars/layouts',
default: 'default.hbs',
pattern: '*.hbs',
partials: '../src/handlebars/partials',
partialExtension: '.hbs'
}))
.use(inPlace({ // Render handlebars content pages
engineOptions: {
pattern: '*.hbs',
partials: '../src/handlebars/partials'
}
}))
.build((error) => { // Build process
if (error) {
console.error(error); // Error handling is required
}
});
This way I can use handlebars partials, variables from frontmatters and helpers in layout files as well as in content pages ๐
Hej there,
using a partial in a template/layout file using
{{> partialname }}
works just fine.But using a partial that way in in a content page doesnโt render the partials content. Is this a bug or on purpose?
This tutorial says it should work content pages too: https://www.sitepoint.com/create-static-site-metalsmith/#partials
Iโm confused ๐
Thanks in advance, Michael