Create variables inside an each loop in a pug template

一笑奈何 提交于 2019-12-24 19:27:11

问题


How can I create variables inside a loop in pug and call them later?

I passed a variable words from an express js server to a pug template and I looped through the variable:

  each word, index in words
    - var spelling = #{word['orth']};
    - var pronunciation = #{word['pron']};

Then I tried to call the variables:

  ul
     #{spelling}

I have this error: SyntaxError: Unexpected character '#'


回答1:


Remove all these unnecessary characters when access word inside the each loop.

  each word, index in words
    - var spelling = word.orth;
    - var pronunciation = word.pron;


来源:https://stackoverflow.com/questions/47604403/create-variables-inside-an-each-loop-in-a-pug-template

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