【问题标题】:Marko Header and Footer IncludesMarko 页眉和页脚包括
【发布时间】:2018-08-21 05:09:22
【问题描述】:

我有两个 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 />

但是,对于main-header,我收到Missing ending "body" tag 的错误,因此显然不允许使用这种类似EJS-partials 的语法。有没有更好的方法来做到这一点,而无需在 每个 路由处理程序中呈现单个 index.marko 文件?

【问题讨论】:

  • 您不能像这样拆分 HTML,因为 Marko 期望 HTML 语法是可解析的(例如,它正在寻找结束标记)。当我有时间时,我会尝试指导您了解包含的工作方式。

标签: express partials marko


【解决方案1】:

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

文档提到使用@tags,它允许传递命名的内容块(如果你想把一些东西放到&lt;head&gt; 和其他东西到&lt;body&gt;),但如果你只有一个内容块要传递,你可以使用默认内容。

您可以创建一个使用&lt;include&gt; 标签来呈现传递给它的内容的布局:

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

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

<custom-layout>
    Content goes here
</custom-layout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多