Reputation: 315
I'm attempting to use Metalsmith global metadata in my twig templates.
I've not found much documentation on using global metadata in templates, regardless of templating language, other than the variable must be referenced as global.KEY
so the following should work.
import metalsmith from 'metalsmith';
import twig from 'metalsmith-twig';
import path from 'path';
process.on('uncaughtException', err => console.error(err));
const siteMeta = {
env: (process.env.NODE_ENV || 'dev').trim().toLowerCase(),
site_title: 'Global Site Title'
};
metalsmith(__dirname)
.clean(true)
.metadata(siteMeta)
.source(path.resolve(__dirname, 'content'))
.destination(path.resolve(__dirname, 'build'))
.use(twig({directory: path.resolve(__dirname, 'src/views/templates')}))
.build(err => {if (err) throw err});
However, both {{global.env}}
and {{global.site_title}}
in my twig templates return empty strings.
Upvotes: 1
Views: 126