Jade / Pug中带有dynamic数据的部分模板

我正在尝试创build两个块的视图。 每个块有不同的实时数据源。 当我在主视图中使用Jade的时候,

extends ../layout block content link(rel='stylesheet', type='text/css', href='/stylesheets/people.css') include ../store/peopleTemplate.pug 

我得到错误

 Cannot read property 'people' of undefined. 

原因是因为数据仍在加载。 如果不包括在复用function中复用数据使用

 res.render(template, { data:localData }); 

该模板未添加到视图中。

如何添加2个或更多的部分视图与dynamic数据从不同的来源到1视图? 谢谢

你可以用mixin来实现这个。

layout.pug

 doctype html html head ... body block content 

宠物partial.pug

 mixin petslist(pets) ul each pet in pets li #{pet} 

pets.pug

 extends layout include pets-partial block content h1 Dogs +petslist(dogs) h1 Cats +petslist(cats) 

https://pugjs.org/language/mixins.html

在翡翠的语法略有不同,然后在哈巴狗2。

经过广泛的研究,帕格/玉模板引擎不支持在一个视图内dynamic模板渲染或多个部分的使用。 这种情况下推荐使用把手。