This is a follow-up question to Create variables inside an each loop in a pug template
I have a problem with a simple if else inside a loop in pug. This is my code:
extends layout
block content
h2 #{item}
each word, index in words
- var spelling = word.orth;
if(item == spelling)
p #{spelling}
else
p does not exist yet
if a word exists, it prints it out correctly but it also prints does not exist yet with it. And if a word does not exist, it prints out does not exist yet 3 times.
Background: I am searching through an xml file for words. The variable item is the user input, the word we are looking for in the xml file.
Aucun commentaire:
Enregistrer un commentaire