2017-05-09 24 views
1

我正在創建一個文檔,這將幫助我減少創建模板時的時間。我想要在一個單獨的文件中使用我在主文件的頭文件中指定的數組來循環代碼塊,但似乎無法使其工作帕格2 - 在循環中推送數組

./src/pug /layout.pug

- const flyouts = [] 
- flyouts.push({variationid: "123", plugin: "none", zone: "ZoneHere", variation: "LargeImage", link: "www.bbc.co.uk", imgloc: "blah.jpg"}); 
- flyouts.push({variationid: "456", plugin: "none", zone: "ZoneHere", variation: "LargeImage", link: "www.bbc.co.uk", imgloc: "blah.jpg"}); 

這裏調用循環,在同一個文件

html 
    head 
     title Hello asd 
    body 
     section 
      // Flyouts 
      each myFlyout in flyouts 
       include components/flyouts  

其中在./src/pug/components/flyouts.pug

012調用的代碼塊
.section(variationid=variationid plugin=plugin zone=zone variation=variation) 
    a(href='asd') 
     img(src='http' alt="Event" width="206" height="148" border="0") 

任何人都可以照亮這一個?

回答

0

Jade/Pug保留父模板的變量範圍,同時包含模板。您正在尋找的變量是myFlyout,它是具有其他值的對象 - variationid,插件等。

您需要使用myFlyout來獲取flyouts.pug中的值。這應該工作 -

.section(variationid=myFlyout.variationid plugin=myFlyout.plugin zone=myFlyout.zone variation=myFlyout.variation) 
    a(href='asd') 
    img(src='http' alt="Event" width="206" height="148" border="0") 
+0

這工程。非常感謝你!! – JimKT