我正在使用带有 webpack 和 handlebars-loader 的车把(用于 webpack 的车把模板加载器。)来实现多页 Web 应用程序。以下是我的视图文件夹(.hbs 文件)的结构
- 意见
成分
- 侧边栏.hbs
布局
- 默认.hbs
- 产品.hbs
索引.hbs
product-1.hbs
product-2.hbs
...
我的问题是我在车把中看到“部分挡块”的奇怪行为。我有两个布局来包装每个页面的主要内容。但我的布局没有在右行加载“部分块”。无论我在布局中使用部分块的何处,把手都会在该位置关闭正文和 html 标记,并在 html 关闭标记之后呈现部分块内容。
下面是我在 body 中加载部分块的示例默认布局:
<!DOCTYPE html>
<html dir="rtl">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{meta.title}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body class="theme-light">
{{#if @partial-block}}
{{> @partial-block }}
{{/if}}
</body>
</html>
我使用默认布局的 index.hbs 文件
{{> layouts/default }}
<main id="index" class="index">
<p>This is index content</p>
</main>
{{layouts/default}}
并渲染 html 文件
<!DOCTYPE html>
<html dir="rtl">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My Test Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body class="theme-light">
</body>
</html>
<main id="index" class="index">
<p>This is index content</p>
</main>
就像我说的,主标签在关闭 html 标签之后出现,这不是预期的行为。