This document is somewhat related to adding a custom signature below all of your posts: http://www.jivesoftware.com/jivespace/docs/DOC-5156 but it will allow you to easily specify custom profile field values to display in any discussion reply.
For example, say you have 2 custom profile field values that you've created and you want them to show up here:
A change like this will simply require some custom theming and it should be very quick and painless! Here is what you will need to do:
1) Create a new global theme (if you don't already have one)
2) Add the /template/forums/thread.ftl template to your global theme
3) Open the thread.ftl template up for editing and scroll down to the way bottom, pasting this macro in:
<#macro renderCustomProfileField fieldid user>
<#assign profile = jiveContext.getProfileManager().getProfile(user) />
<#if profile.get(fieldid?long)?exists>
<#assign profileFieldValue = profile.get(fieldid?long)>
<#assign profileField = jiveContext.getProfileFieldManager().getProfileField(fieldid?long) />
${profileField.name}:
<#if profileFieldValue.value?exists>
${profileFieldValue.value?html}
<#elseif profileFieldValue.values?exists>
<#list profileFieldValue.values as value>
${value?html}<#if value_has_next>,</#if>
</#list>
<#else>
Empty
</#if>
</#if>
</#macro>
If you want to change how the profile fields show up, this is what you will want to go back and modify.
4) Scroll up inside the same template to the following code:
<div class="jive-author">
<#if !message.user.anonymous>
<span class="jive-author-avatar-container">
<@jive.userAvatar user=message.user size=46 class='jive-avatar'/>
<#if statusLevelEnabled>
<@jive.userStatusLevel user=message.user/>
</#if>
</span>
<div class="jive-username-link-wrapper">
<@jive.userDisplayNameLink user=message.user />
</div>
<em>${jiveContext.getForumManager().getUserMessageCount(message.user)} <@s.text name="forum.thrd.posts_since.label"/> <br/>${message.user.creationDate?date}</em>
<#else>
<span class="jive-author-avatar-container">
<@jive.userAvatar user='' size=46 class='jive-avatar'/>
</span>
<div class="jive-username-link-wrapper">
<span class="jive-guestname"><@renderGuestDisplayName message=message/></span>
</div>
</#if>
</div>
and change it so it looks like this:
<div class="jive-author">
<#if !message.user.anonymous>
<span class="jive-author-avatar-container">
<@jive.userAvatar user=message.user size=46 class='jive-avatar'/>
<#if statusLevelEnabled>
<@jive.userStatusLevel user=message.user/>
</#if>
</span>
<div class="jive-username-link-wrapper">
<@jive.userDisplayNameLink user=message.user />
</div>
<em>${jiveContext.getForumManager().getUserMessageCount(message.user)} <@s.text name="forum.thrd.posts_since.label"/> <br/>${message.user.creationDate?date}<br/><br/>
<@renderCustomProfileField fieldid=5001 user=message.user /><br/>
<@renderCustomProfileField fieldid=5002 user=message.user />
</em>
<#else>
<span class="jive-author-avatar-container">
<@jive.userAvatar user='' size=46 class='jive-avatar'/>
</span>
<div class="jive-username-link-wrapper">
<span class="jive-guestname"><@renderGuestDisplayName message=message/></span>
</div>
</#if>
</div>
As you can see, the <em> tag was extended down to include the two custom profile fields (<@renderCustomProfileField fieldid=5001 user=message.user /> and <@renderCustomProfileField fieldid=5002 user=message.user />).
You can add as many custom profile field displays as you want to here, just swap out my profile field IDs (5001, 5002) with your own profile field IDs and everthing should get hooked up correctly:
You will need to repeat step 4 for the following code as well (the code in #4 is for the initial post but not the replies):
<div class="jive-author">
<#if !message.user.anonymous>
<span class="jive-author-avatar-container">
<@jive.userAvatar user=message.user size=46 class='jive-avatar'/>
<#if statusLevelEnabled>
<@jive.userStatusLevel user=message.user/>
</#if>
</span>
<div class="jive-username-link-wrapper">
<@jive.userDisplayNameLink user=message.user />
</div>
<em>${jiveContext.getForumManager().getUserMessageCount(message.user)} <@s.text name="forum.thrd.posts_since.label"/> <br/>${message.user.creationDate?date}<br/><br/>
<@renderCustomProfileField fieldid=5004 user=message.user /><br/>
<@renderCustomProfileField fieldid=5005 user=message.user />
</em>
<#else>
<span class="jive-author-avatar-container">
<@jive.userAvatar user='' size=46 class='jive-avatar'/>
</span>
<div class="jive-username-link-wrapper">
<span class="jive-guestname"><@renderGuestDisplayName message=message/></span>
</div>
</#if>
</div>
If you want this to display for other content types/other places on the thread page you should be able to jsut move around the <@renderCustomProfileField > calls and the display will move along with it. Enjoy!
-Todd
Hey David,
I only tested this on SBS 3.0.x but it looks like it might work for 2.5.x as well (maybe with a few small tweaks).
The renderCustomProfileField macro is one that I created and posted up near the top of the doc:
<#macro renderCustomProfileField fieldid>
<#assign profile = jiveContext.getProfileManager().getProfile(message.user) />
<#if profile.get(fieldid?long)?exists>
<#assign profileFieldValue = profile.get(fieldid?long)>
<#assign profileField = jiveContext.getProfileFieldManager().getProfileField(fieldid?long) />
${profileField.name}:
<#if profileFieldValue.value?exists>
${profileFieldValue.value?html}
<#elseif profileFieldValue.values?exists>
<#list profileFieldValue.values as value>
${value?html}<#if value_has_next>,</#if>
</#list>
<#else>
Empty
</#if>
</#if>
</#macro>
So you'll need to put that in the thread.ftl or other FTL that you attempt to implement this in.
Todd-
Thanks!
I'm excited to put this in. Can the label "Awesome factor" and "location" be removed so only the value shows?
Mark
Sure, these values are automatically generated within the macro. You'll just need to modify it to something like this:
<#macro renderCustomProfileField fieldid>
<#assign profile = jiveContext.getProfileManager().getProfile(message.user) />
<#if profile.get(fieldid?long)?exists>
<#assign profileFieldValue = profile.get(fieldid?long)>
<#if profileFieldValue.value?exists>
${profileFieldValue.value?html}
<#elseif profileFieldValue.values?exists>
<#list profileFieldValue.values as value>
${value?html}<#if value_has_next>,</#if>
</#list>
<#else>
Empty
</#if>
</#if>
</#macro>
All I removed was these two lines:
<#assign profileField = jiveContext.getProfileFieldManager().getProfileField(fieldid?long) />
${profileField.name}:
Good luck!
-Todd
Todd-
Works great! Our Moderators thank you!
I noticed two things. The first of which I believe you mentioned in the original document.
Hey Mark,
Nice catch. I've updated the code above, it was incorrectly using the original posters information for all of the calls to the macro. You'll want to update the macro as I've done above (adding the user parameter and calling getProfile on this value).
Yeah, unfortunately if you use too many values (such that it extends lower than the first post text) you'll need to code up some CSS to handle it. Thanks!
-Todd
hi Todd,
Our requirement is to show "FirstName LastName" field as "Title. FirstName LastName". This change should reflect across all pages wherever name is displayed such as Profile, vCard, RecentActivities, Disscussion etc.
The approch mentioned above, looks like I need to change many FTL files. Wondering if there is a global way of doing (instead of changing many FTL files)?