0

I'm using Underscore's templating engine for my Metalsmith website and I'm having a bit of a trouble accessing the footer partial. I'm receiving an error message saying:

ReferenceError: footer is not defined

How should I call it? What am I doing wrong?

Thank you.

Here's the templating part of my Metalsmith build file:

...
.use(layouts({
  engine: 'underscore',
  directory: 'templates',
  partials: 'templates/partials'
}))

Here's my folder structure:

posts/
src/
templates/
- base.tpl.html
- partials/
-- footer.tpl.html

Here's a post example:

---
title: My First Post
date: 2012-08-20
layout: base.tpl.html
---

# This is my title

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur sed magna vel eros malesuada fringilla.

And here's my html page:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title><%- sitename %></title>
  </head>
  <body>
    <h1>Hello, world!</h1>

    <%= contents %>

    <% footer %>    <---- THIS IS UNDEFINED
  </body>
</html>
Alexandru
  • 833
  • 1
  • 8
  • 24

1 Answers1

1

I guess you need to use the option partialExtension in your build file:

...
.use(layouts({
  engine: 'underscore',
  directory: 'templates',
  partials: 'templates/partials',
  partialExtension: '.tpl.html'
}))

https://www.npmjs.com/package/metalsmith-layouts#partialextension

…because when the plugin processes <% footer %> it really just searches for a file named footer instead of footer.tpl.html

(not tested)

Breaker222
  • 1,334
  • 1
  • 14
  • 23