How to use for loop including files in jade (pug)?

為{幸葍}努か 提交于 2019-12-13 08:19:00

问题


I would like to use a for loop to include jade files each after the other such as slide-1, slide-2, slide-3 etc.

I tried this but it failed:

for(var i = 1; i < 4; i++) {
  include('slide-' + i)
}

What's the correct syntax?

Thank you in advance!


回答1:


If you need to iterate a certain number of times, you'd need to define your own function to do so.

html
  title Whatup
  -function range(start, end) {
  -    var arr = [];
  -    for (var i = start; i < end; i++) arr.push(i);
  -    return arr;
  -  }
  each i in range(1, 4)
      include('slide-' + i)


来源:https://stackoverflow.com/questions/43967240/how-to-use-for-loop-including-files-in-jade-pug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!