Marko页眉和页脚包含

时间:2018-03-13 03:21:30

标签: express partials marko

我有两个Marko组件,我们想要在Express服务器上呈现时包含在其他组件中:<main-header/><main-footer />

components/main-header/index.marko如下:

<lasso-page />
<!DOCTYPE html>
<html>
    <head>
        <lasso-head />
    </head>
    <body>
        <nav>...</nav>

components/main-footer/index.marko是:

    <footer>...</footer>
    <lasso-body />
  </body>
</html>

我想在特定路线上呈现的页面如下所示:

<main-header />
    //component content
<main-footer />

但是,我Missing ending "body" tag的错误为main-header,所以很明显这种类似EJS-partials的语法是不允许的。如果没有在每个路由处理程序中呈现的单个index.marko文件,是否有更好的方法来执行此操作?

1 个答案:

答案 0 :(得分:1)

以下是使用布局的文档: https://markojs.com/docs/core-tags/#layouts-with-nested-attributes

文档提到使用@tags允许传递命名内容块(如果您想将一些内容放入<head>,将其他内容放入<body>),但如果您只有一个要传递的内容块,可以使用默认内容。

您可以创建一个使用<include>标记来呈现传递给它的内容的布局:

<html>
<body>
    <include(input.renderBody)/>
</body>
</html>

然后使用布局,传递正文内容:

<custom-layout>
    Content goes here
</custom-layout>
相关问题