Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS Flask Basics Character Builder Items

If statement

Hi,

I am struggling to understand what is going on in this line of code:

{% if saves.get(category) == choice %} checked {% endif %}

Why would the if statement check if what has been saved is equal to choice? In that regard, how do we make sure that it will check the item that we have selected and not other?

Thanks for your help?

1 Answer

Daniel Schirmer
Daniel Schirmer
4,364 Points

It's not totally clear, because I couldn't see the code for the Update button, but the Update button should save the item that is clicked into the cookie. saves.get(category). So I think it would go like:

  1. User clicks an item picture in a category and then clicks Update
  2. Update button saves the item name/category into a cookie (via the save function with url redirects)
  3. The if statement in question checks the cookie for a match {'shorts': 'yellow'} and makes "checked" the value from the key-value pair in the cookie.