Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDavid Aguirre
8,170 Pointsindex.pug For Each User in Users declaration and express route
Hi there
I have a question regarding how the declaration in the views folder for the index file is being used.
I see that the index.pug file has a "user" in singular that I cannot relate directly to the users const variable declaration in app.js file and with the users.users Json data attribute from the JSON file.
body ul each user in users li(class="user") i(class="material-icons") account_box h3 #{user.name} p #{user.username} p #{user.bio}
Thanks in advance for any feedback given to this server.
1 Answer
James Crosslin
Full Stack JavaScript Techdegree Graduate 16,882 PointsSorry nobody got around to answering this question earlier, but this portion of the index.pug file is what allows you to reference the user
variable:
each user in users
li(class="user")
i(class="material-icons") account_box
h3 #{user.name}
p #{user.username}
p #{user.bio}
each user in users
In this snippet from the file, each
is a forEach method. It is cycling over each object in users
and performing the action of creating a list item for each of them. Hope this helped!