Forum Discussion
There isn't a config option to do this for message posts but you could customize your message page to show first name and last name.
You would need to create a custom component that pulled the user's first/last name from their profile setting then add it to the Forum Message page. Before you do that - I can help you through the technical steps if you need it - you should think about a couple of things.
1. Do your users have first name and last name filled out? A lot users do not enter personally identifiable information in their community accounts.
2. How will your users feel if you start displaying their name? Do you want to add an option for turning this off or having users opt in before this is displayed?
There is a lot of back and forth on "real names" in comments and posts. Make sure you know what you are getting into :)
Hey Kaela,
Thanks for such a quick response! In regards to your questions, thanks for bringing up those points, as they relate to my community:
1. Foruntately we have the first and last name for all of our users as we use SSO tied to our existing registration process (which requires a name and is usually accurate). Additionally, half of our user base are our interntal customers which have 100% accurate information.
2. That's an interesting thought but I feel pretty comfortable switching it on as, by default, we show first and last name on their user profile page.
Also, I'm assuming the custom component could be placed everywhere a username is used?
Thanks,
Colin
- KaelaC14 years agoLithium Alumni (Retired)
Hi Colin,
Sorry for the late reply. There are two parts to this that you will need to do. The first is create a custom component that pulls the user's first and last name. Like Adam said, you can use env.context.message.author to figure out who the message author is.
<#assign allowed=rest("/users/id/${env.context.message.author?c}/profiles/name/name_first/allowed").value /> <#if allowed?trim == "true"> <#assign first_name= rest("/users/id/${env.context.message.author?c?c}/profiles/name/name_first").value!"" /> <#assign last_name= rest("/users/id/${env.context.message.author?c?c}/profiles/name/name_last").value!"" /> </#if> ${first_name} ${last_name}
The first part of this look to see if the current user has permission to see the author's profile information. Next, it amakes rest calls to get that information. Lastly, it displays the first and last names.
The second part is to add this new component to the ForumMessage page in studio. I'm having a hard time finding it myself so you may need to ask support to do that (or maybe I'm just going blind).
- cgmcconnell14 years agoExpert
Hi Kaela,
I tried using this in studio but I am being given an error message, essentially what I did was:
1. Create a new custom content module and pasted in the code you outlined above,
2. Adding a custom component on the forum message page.
When I view a forum message, I'm shown an error message, this bit below is a segment of that:
Expression first_name is undefined on line 1, column 3 in preview. The problematic instruction: ---------- ==> ${first_name} [on line 1, column 1 in preview] ----------
Do you have any ideas for fixing this?
Thanks,
Colin- AdamN14 years agoKhoros Oracle
Hi Colin,
Freemarker gets a little upset when you try to access "missing" values. If first_name is undefined by the time you get to the last line, it means that the the assignment statements were never executed. Which in turn would mean that allowed is not being assigned a value of "true" in the first REST call.
This could be due to a couple reasons. First, I think we may need to tweak a few of your statements to use ${env.context.message.author.id?c}, in order to obtain the id of the user for the REST API calls.
Second, this could also be due to the user's privacy preferences. I know you mentioned previously that you were comfortable with showing the user's first and last name anyway, so you could potentially remove the "allowed" check. My suggestion, though, would be to leave it in and allow users to set their own privacy preferences. In this case, you'd probably want to add an else statement to handle what happens if they aren't allowed to view the first and last name.
So all in all, it might look something like this:
<#assign allowed=rest("/users/id/${env.context.message.author.id?c}/profiles/name/name_first/allowed").value /> <#if allowed?trim == "true"> <#assign first_name= rest("/users/id/${env.context.message.author.id?c}/profiles/name/name_first").value!"" /> <#assign last_name= rest("/users/id/${env.context.message.author.id?c}/profiles/name/name_last").value!"" /> ${first_name} ${last_name} <#else> ${env.context.message.author.login} </#if>
Like Kaela's code, this sample code is intended to get you going in the right direction. It's not been tested out, and you may need to tweak a bit to suit your exact needs.
Here are the references for the concepts I mentioned in this post:
- Info about the env context, which allows you to get the author info from the message - http://lithosphere.lithium.com/t5/Developer-Knowledge-Base/Context-objects-for-custom-components-env/ta-p/9321
- Info about the user context, which allows you to get the id and login once you have the author from the env context - http://lithosphere.lithium.com/t5/Developer-Knowledge-Base/Context-objects-for-custom-components-user/ta-p/9339
- Info about "missing" variables in Freemarker - http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing
I hope this helps!
- KaelaC14 years agoLithium Alumni (Retired)
Ooops sorry, yes. I should have defined my varialbles first.... and Kaela fails CompSci 101
- cgmcconnell14 years agoExpert
Thanks very much, it's working great.
Colin
- AdamN14 years agoKhoros Oracle
Hi Colin,
It really depends on how you construct the component. There are a few different context objects you can make use of with freemarker:
- env.context.message.author - if the component is within the context of a message, this will give you the author of the message.
- page.context.user - if you place the component on the ViewProfilePage, this will give you the user whose profile page is currently being displayed
- user.id - On any page, this will give you the id of the user viewing the page
So you could very well construct a single component that handled a bunch of different cases. However, depending on exactly what you're trying to accomplish, it might be easier to just have separate, specific-use components.
I hope this helps!
Related Content
- 6 years ago