Hi guys!
I need a good way to check whether a user is logged in and deliver appropriate content. I've been looking around and I've seen a number of different use cases discussed but not really a generic overview of how to do it. I've seen several different methods for doing it as well but I've not found any discussion about best practices or preferred methods. I've also not seen any examples that don't require writing custom snippets. Does this functionality not exist out of the box? Can it be done with some kind of conditional tag in the template or do I have to write a snippet?
Right now my plan is to put classes in my markup to specify what should be shown and when, e.g. loggedIn and notLoggedIn, and then write a snippet that does nothing but deliver one line of CSS to the client: either .loggedIn{display:none;} or notLoggedIn{display:none;}. This seems like a less than ideal solution to me but it should work.
If I go ahead with the aforementioned plan, which method should I use to do the checking? I've seen the following:
if($modx->getLoginUserName()){ ...
if ($modx->user->hasSessionContext($modx->context->get('key')) ){ ...
if ($modx->getLoginUserID()) {...
There may be others as well. Any input will be appreciated.
Thanks!