Return to Jive Software

Currently Being Moderated

Showing custom profile field values in discussion replies

VERSION 2  Click to view document history

Created on: Aug 13, 2009 8:46 AM by Todd West - Last Modified:  Aug 13, 2009 3:25 PM by Todd West

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:

 

profilefieldvalues_discussion_1.png

 

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:

 

 

profilefieldvalues_discussion_2.png

 

 

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

Average User Rating
(1 rating)
My Rating:
David Montgomery David Montgomery  says:
Todd - great tip!  What version(s) of Clearspace/JiveSBS will this work for?  Also, is <@renderCustomProfileField > available out of the box in the API, or does it require any additional code?
Todd West Todd West  says in response to David Montgomery:

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.

Anthony Dotson Anthony Dotson  says:
Nice! Much cleaner than adding in the body of the post. Great post.
Mark Mark  says:

Todd-

 

Thanks!  I'm excited to put this in.  Can the label "Awesome factor" and "location" be removed so only the value shows?

 

Mark

Todd West Todd West  says in response to 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

Mark Mark  says in response to Todd West:

Todd-

 

Works great! Our Moderators thank you!

 

I noticed two things. The first of which I believe you mentioned in the original document.

 

  • If you display the same custom fields for the reply posts it will show the root poster's values.
    • I assume this can be resolved by creating a second macro for the reply poster?
  • If the root or reply poster doesn't create at least 3 lines of text for 3 custom profile fields shown, the values will flow out of the root post/reply post field and into the box below thus indenting the first response making it look threaded.
    • I assume this possibly could be resolved by setting a minimum post box size?
Todd West Todd West  says in response to Mark:

Hey Mark,

I assume this can be resolved by creating a second macro for the reply poster?

 

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).

 

 

I assume this possibly could be resolved by setting a minimum post box size?

 

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

kodalis11 kodalis11  says in response to Todd West:

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)?

Todd West Todd West  says in response to kodalis11:
I believe that you would need to end up modifying a few different FTL files in order to get it to show up in all of those locations. In order to change the way that names are displayed throughout the application you might be able to just modify the userDisplayNameLink macro in jive-macros.ftl to change the way the link is displayed (just add my macro above into jive-macros and then utilize it in userDisplayNameLink). I haven't tested this myself but I am thinking that would likely cover most of the cases you've described. Good luck!

Bookmarked By (1)

More Like This

  • Retrieving data ...