2016-07-27 36 views
1

我試圖用2個塊創建視圖。每個塊有不同的實時數據源。當我使用Jade`s包括主視圖中,:Jade/Pug中帶有動態數據的部分模板

extends ../layout 

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

我得到錯誤

Cannot read property 'people' of undefined. 

的原因是因爲數據仍在加載。如果排除包含和替代功能復甦的數據使用

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

模板不添加到視圖。

如何將來自不同來源的動態數據添加到2個或多個部分視圖到1個視圖?謝謝

回答

0

經過大量研究,帕格/翡翠模板引擎不支持動態模板渲染或在一個視圖內使用多個部分。此場景推薦使用把手。

2

你可以用mixins來實現這一點。

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.