0

我为我的Metalsmith网站使用了Underscore的模板引擎,并且在访问footer部分时遇到了一些问题。我收到一条错误消息:如何在Metalsmith中使用下划线的部分?

ReferenceError: footer is not defined 

我应该怎么称呼它?我究竟做错了什么?

谢谢。

这是我的Metalsmith构建文件的模板部分:

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

这里是我的文件夹结构:

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

这里有一个职位例如:

--- 
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. 

这是我的html页面:

<!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> 

回答

0

我猜你需要使用的选项partialExtension请在生成文件:

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

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

...因为当插件处理<% footer %>它真的只是搜索名为footer而不是文件footer.tpl.html

(未测试)

相关问题