This is my code in index.jade:
- each question in questions
- console.log('Question in index.jade: ', question);
!=partial('question', question)
And this is my code in question.jade:
- console.log('Question in question.jade: ', question);
For some reason, both variables question are different. Am I doing something stupid?
You need to put the
questionvariable in an object with a key ofquestionand pass that to the second parameter of the partial function. For example:Then the partial view will have access to the question variable you want. Also, assuming you are using jade with express and the partial is the only thing in your
eachloop, there is a shorthand for that:This will automatically render the partial once for each element in the
questionsarray.