I’m working on a site that needs to detect whether a user is logged on or not to the current context (or a specific named context, if that’s easier) and print data based on that (e.g., “Log In” vs. “Log Out”). Specifically, I need to be able to do this via tag syntax (for use in chunks).
Here are a couple ways to detect this that I have seen, but they don’t work exactly as I need them to (relative to the context). I was wondering if there is a “best” way somewhere:
[[!+modx.user.id:is=`0`:then=`...not logged in...`:else=`...logged in...`]]
[[!If?
&subject=`[[+modx.user.id]]`
&operator=`EQ`
&operand=`0`
&then=`...not logged in...`
&else=`...logged in...`
]]
Note, if a user is logged in to the manager context, but not the main website context, modx.user.id is set to the user’s ID on the manager context, which is the issue that I have with the above code examples.