3

I notice in the template examples that user, account and currentUser are all being used, but not seeing clear documentation on these. Can someone perhaps explain the difference?

Example User Registration Form uses {{ account.username }}

Example User Profile Form uses {{ user.username }}

and there is a Global Variable called {{ currentUser.username }}

I assume that user is perhaps just an alias to currentUser (unless explicitly defined otherwise)? And that account is something that is used exclusively for user/saveUser?

The reason I ask is that I'm creating edit profile pages, and want to make sure they are secure. Seems like just using user is enough, as that appears to always be populated correctly with the currentUser data; and if not logged-in it redirects to the log-in page.

Thanks.

7

user and currentUser are exactly the same. They contain the UserModel of the currently logged in user.

Why are they exactly the same? Originally, user was the preset value for the current user. However, there were many cases of people manually setting a value for user (often in the context of a for loop through a group of users), and therefore overwriting the preset value. So P&T introduced currentUser as an alias which was much less likely to be overwritten.

account will only exist on the User Registration Form. Its value is automatically set when the form is submitted. account represents the values entered during the attempted registration (whether the registration was successful or not).

For the sake of your Edit Profile pages, you'll want to use currentUser.

| improve this answer | |
  • 2
    We used to only set user to the currently logged-in user, but after receiving some feedback that it wasn’t descriptive enough we decided to also add currentUser in Craft 1.2. We’ve tried to update all of the documentation to reference currentUser instead of user but the User Profile Form was apparently overlooked. I just went in and updated it. – Brandon Kelly Sep 25 '14 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.