我有两个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-部分。是否有更好的方法来做到这一点,而不需要在每个index.marko路由处理程序的中呈现一个文件?
发布于 2018-03-22 06:07:23
下面是关于使用布局的文档: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>https://stackoverflow.com/questions/49247795
复制相似问题