metalsmith / layouts

A metalsmith plugin for layouts
MIT License
116 stars 49 forks source link

Passing variables to templates #52

Closed azappa closed 8 years ago

azappa commented 8 years ago

Using your plugin I've replaced the metalsmith-jade one but now I don't know how to pass variables to my .jade templates. The code I wrote is:

.use(
    layouts({
      engine: 'jade',
      directory: './_layouts',
      partials: './_partials',
      pretty: true,
      locals: {
        devel: process.env.MODE,
        test: 'pippo'
      }
    })
  )

but in template I don't know how to print them... In my template files locals seems to be passed so I tried

pre=JSON.stringify(locals)

or

pre=locals.toString()

but no success. Is there any other options or something related to metalsmith-in-place that I don't know?

Thank you.

ismay commented 8 years ago

Easiest way to pass variables is to use frontmatter:

---
title: A Catchy Title
draft: true
---

This'll define the variables title and draft for example. See http://www.metalsmith.io/ for an example.

Or if you want to set global variables, use the .metadata() method. Documentation here, and example here. Closing, but feel free to let me know if you have further questions.