- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2015 05:08 AM
I assume you have tried using g_user? Are you able to share what you tried? I did a bit of testing and g_user is available.
For anything like this where you need a standard piece of info that won't change in the client session it's much easier and better practice to just add a variable to the document on the server in the layout (or better, a UI macro that you include in each layout).
E.g. Content Management -> Design -> Layouts -> select your layout (you could also go via your CMS page layout field).
At the top of the XML, under the <j:jelly... tag, add this:
<script>
var u_is_logged_in = ${gs.isLoggedIn()};
</script>
Then in your script, you simply need to reference is_logged_in.
if (u_is_logged_in) {
// do some stuff.
}
It's also best, if possible, to hide things from your users by default and expose them if they are logged in. This way, no one sees stuff when the page is loading or if the script fails. Your specific use case will help determine this.