Current status of the Ning Platform is always available on the Ning Status Blog.

FORUM

NC for Hire

Hi there,

Yep, I've been M.I.A from some time now, yet again, due to my work and college stuff. So, today, I will be sharing on how can we use the ning.CurrenProfile variable.

The Wonders of User Profile Variable

You can see these variables popping out here and there in scripts made by others. But what exactly are they and how can we utilize it?

They are what we called Javascript associative array which holds information of  a user, they store:

Your Ning ID, name, gender, location, country, profile photo, profile url and age.

For example, this is mine:

"CurrentProfile":{"id":"18abpibelhnjw","profileUrl":"http:\/\/creators.ning.com\/profile\/ElsonTan","location":"","age":17,"gender":"m","fullName":"Elson Tan","photoUrl":"http:\/\/api.ning.com:80\/files\/xsJ3TfqGR*rbjPXpvvzxFbUOnVIhE6M5B9EsEOuYlU7liB96qnj-wpwlwPvpDpL1v7bfclBWFf5TIIIhJ23GkaUjKzk0S9Lk\/avatar.png?crop=1%3A1","country":"MY"}

You can see yours by view sourcing any page on Ning network, and search for "CurrentProfile".

How do we use this?

We can access it using javascript for example:

<script>

alert("This is my name! " + ning.CurrentProfile.fullName);

</script>

Here's the list of the variables we can access to:

Full Name : ning.CurrentProfile.fullName

Ning ID : ning.CurrentProfile.id

Profile URL: ning.CurrentProfile.profileUrl

Location(state, if provided): ning.CurrentProfile.location

Country: ning.CurrentProfile.country

Age: ning.CurrentProfile.age

Photo URL: ning.CurrentProfile.photoUrl

Gender: ning.CurrentProfile.gender

Usage

1. Restricting access to certain pages by determining their age group

<script>

if(ning.CurrentProfile.age < 18){

    window.location.href = '/'; //redirect to home page
}

</script>

(P/S: Samething with ning.CurrentProfile.gender, just use == 'm' or == 'f'

2. Welcome the user

Place this html inside a textbox on home page:

Welcome, <div class="thisusername"></div>.

And, place this script into your custom code(below):

<script>

x$('.thisusername').html(ning.CurrentProfile.fullName);

</script>

3. The above example shows user's name, but what about their photo too?

Same as above, put this into any place you want their thumbnail to show up, HTML:

<div class="userthumb"></div>

Script:

<script>

var sizeofthumb = 50;

x$('.userthumb').html('<img src="'+ ning.CurrentProfile.photoUrl +'&width='+ sizeofthumb +'">');

</script>

This will produce:

<div class="userthumb"><img src="https://api.ning.com/files/DqaYw0w2aP**r6mMPdBXIEN6QNtWFBTW-EeO7W9PlR85osj-U3MJv2jSslKaWCU8VIMK3h6Q9dHvSMfkj6HgD6p5i2IhoQMV/1059735205.png"></div>

Produces a thumbnail with size of 50x50px

4. Determine if current user is a guest/member

<script>

if(ning.CurrentProfile === null){

alert('you are guest');

} else {

alert('you are user');

}

</script>

5. Create user profile link

HTML:

<a href="#" class="userprofilelink">My Profile</a>

Script:

<script>

x$('a.userprofilelink').attr('href', ning.CurrentProfile.profileUrl);

</script>

That's it, there are still more ways to use these guys, its all based on your ideas. 

Happy Coding. 

You need to be a member of Ning Creators Social Network to add comments!

Join Ning Creators Social Network

Email me when people reply –

Replies

  • Hey Elson, great to see you!  Hope everything's going well with your studies.  It's not easy but definitely worth the effort in the long run and we'll say "we knew him when....".  LOL  So help a non--coder like myself:  Where will this data appear?  In our Google analytics or in our member data?  My caffeine hasn't quite kicked in yet so I'm a little fuzzy.

    • NC for Hire

      Hi Kos,

      these are all javascript variables, you can access them via javascript code in your custom code area. Just try our the scripts(put them into your custom code[below] box)provided you will understand how it works. ;)

      P/S for those which has HTML, just place it in a custom textbox anywhere on your network.

      Enjoy.

      • NC for Hire

        ok.. here's an idea....just thinkin out loud.. how might I add the users location from profile beside their name on photo uploads? 

        I was considering injecting something like this through language editor:

        <div class="thatuserlocation"></div>

        <script>

        x$('.thatuserlocation').html(ning.CurrentProfile.location);

        </script>

        would this work?

  • oops ok I somehow copied a period . that I didn't need.  ok here's how it looks. 

  • Always great tips! Glad to see you back and love what you've done to your new site btw! Hope your studies are going well. Will be utilizing the welcome script for sure.

    -Jords

  • This reply was deleted.
    • You rock Elson. Thanks man. I am still waiting for somebig news from your end. (Erewards for Ning3.0).

  • NC for Hire

    this is a wonderful tip Elson!  It makes me wonder if something similar might be accomplished with a member map (ie. pulling in profile photo to fusion table).. hmmm

    any thoughts?

  • This code is not working for me. Can you or somebody please help me :) I will love to put this in a profile block. 

    • Hi there!

      There are several codes presented in teh tip, which one are you trying to use?

      Best wishes,

      Ning Team.

This reply was deleted.

Announcements

 

Some interesting articles related to community management, digital marketing etc. could be found in our digest. Don't hesitate to leave a feedback so we would know that we should continue :-)

Latest Activity

Anastasiia_NING support posted a discussion in NING BUSINESS CLUB
- Light. Try to make shots during morning and afternoon (дневные) hours. It will strongly influence…
2 hours ago
Alex replied to Alex's discussion
Missing images???
"Yes, I also reported that to Ning Support a while back - but not fixed yet."
16 hours ago
⚡JFarrow⌁ replied to ⚡JFarrow⌁'s discussion
Trick: Perfect Combination for Bringing Your Community Into a Facebook Page
"It seems like the only way people respond to posts inside this community anymore is if it is a comp…"
18 hours ago
Fabricio Giugni replied to Fabricio Giugni's discussion
Like button is not working
"Hi There,
I took about a minute to find where it was. It works better when Like button cames under…"
21 hours ago
marie replied to marie's discussion
Landing page navigations do not show menus on mobile screen
"here is the new color : 
rgb(35, 85, 117)
or
#235575"
22 hours ago
marie replied to marie's discussion
Landing page navigations do not show menus on mobile screen
"OMG Anastasiathat is amazing !!!thank youJust the color needs to be changed (sorry I have changed t…"
22 hours ago
marie replied to marie's discussion
Landing page navigations do not show menus on mobile screen
"OMG Anastasia
that is amazing !!!
thank you
I will go into the code to modify the background colour…"
22 hours ago
Anastasiia_NING support posted a discussion in NING BUSINESS CLUB
Here is the list with their names and links to the resources where you can find information about w…
23 hours ago
Anastasia_Ning_Support replied to marie's discussion
Landing page navigations do not show menus on mobile screen
"Hello!
My colleague has made some changes to make it look as close as possible to the picture you s…"
23 hours ago
Anastasia_Ning_Support replied to Fabricio Giugni's discussion
Like button is not working
"Hello!
My colleague has relocated the Like button as you asked, please check it. 
Best regards,
The…"
23 hours ago
Thisisbully replied to Alex's discussion
Missing images???
"Also when you upload say more than one photo at once it will show the first photo u select that man…"
yesterday
Anastasia_Ning_Support replied to Fabricio Giugni's discussion
A list of Problem just growing...
"Hello!
I am sorry, I will insert screenshots into my reply. 
"I can see that you have already check…"
yesterday
More…

Meanwhile, you can check our social media channels