使用 Handlebars.js 将一个 html 文件包含到另一个 html 文件中

Pie*_*rre 5 node.js handlebars.js

在 PHP 中,很容易将一个文件包含在另一个文件中以避免使用include关键字的代码冗余。使用 Handlebars.JS 在 Node.JS 中是否有类似的解决方案?

Nic*_*ett 11

从您的问题看来,您正在寻找 handlebars partials。例如,请查看https://github.com/donpark/hbs/tree/master/examples/partial

简而言之,你会有一些看起来像:

索引.hbs:

<!DOCTYPE HTML>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Your Website</title>
</head>

<body>
{{> header}}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

在哪里{{> header}}引用header.hbs部分。