Outputting custom user fields?

maxwolfie

Active member
I was not sure where to post, basically I guess you could call this related to a modification that I am using called "XenStaff" however it is no longer supported and the forum is closed. What I am asking, however is not really specific to this modification, but rather just a general query as to how to do something.

What I am looking to do is output custom fields that the user has filled out, and note them next to their names on the following page:

http://www.hackslashrepeat.com/guildmembers/

For example, for Greg (me), I have a number of Custom User Fields set up that I've filled out, I want those fields to display their names and outputs on the Guild Members page above. The information is basically my gaming name, account name or Battle Tag (in the case of Diablo 3). If you go to any of my threads, such as this one, you will see these custom fields under my avatar. These are the ones that I want to have outputted to the Guild Members page, next to my name. People can then go to the Guild Members page and add everyone to their in-game friends lists, rather than manually trawling the forums to try and find everyone in the guild.

Please see the attached image to see what I mean.

The code below is the index for the Guild Members (XenStaff_index) template/page:

Code:
<xen:title>{$xenOptions.staffpageTitle}</xen:title>
<xen:h1>{$xenOptions.staffpageTitle}</xen:h1>
 
<xen:description>{$xenOptions.staffpageDescription}</xen:description>
 
<xen:if is="{$xenOptions.staffnoticeActive}">
 
    <xen:if is="{$xenOptions.displaystaffNotice}">
        <p class="importantMessage">
        {$xenOptions.displaystaffNotice}
        </p>
    </xen:if>
 
</xen:if>
 
<xen:require css="XenStaff_index.css" />
<xen:require css="member_list.css" />
 
<xen:foreach loop="$staffgroups" value="$staffgroup">
 
<div id="{$staffgroup.title}" class="section">
    <h2 class="staffHeading">{$staffgroup.title}</h2>
 
        <ol class="section memberList">
 
        <xen:foreach loop="$staffgroupsuserids" value="$staffgroupsuserid">
 
            <xen:if is="{$staffgroupsuserid.user_group_id} == {$staffgroup.group_id}">
         
                <xen:foreach loop="$staffuserinfo" value="$user">
 
                    <xen:if is="{$staffgroupsuserid.user_id} == {$user.user_id}">
 
                <xen:include template="member_list_item">
                    <xen:set var="$noOverlay">1</xen:set>
                </xen:include>
 
                    </xen:if>
 
                </xen:foreach>
 
            </xen:if>
 
        </xen:foreach>
 
    </ol>
</div>
 
</xen:foreach>
 
<xen:sidebar>
 
          <xen:if is="{$staffonline}">
 
        <div class="section staffOnline avatarList">
            <div class="secondaryContent">
                <h3>{$xenOptions.staffonlineHeading}</h3>
                <ul>
 
                    <xen:foreach loop="$staffonline" value="$user">
                        <li>
                            <xen:avatar user="$user" size="s" img="true" />
                            <a href="{xen:link members, $user}" class="username">{xen:helper richUserName, $user}</a>
                            <div class="muted">{xen:helper userTitle, $user}</div>
                        </li>
                    </xen:foreach>
 
                </ul>
            </div>
        </div>
 
          </xen:if>
 
</xen:sidebar>

And I'm guessing that these lines from message_user_info (below) can be used in the above, but I'm just not sure how.

Code:
            <xen:if is="@messageShowCustomFields AND {$user.customFields}">
            <xen:hook name="message_user_info_custom_fields" params="{xen:array 'user={$user}', 'isQuickReply={$isQuickReply}'}">
   
                <xen:foreach loop="$userFieldsInfo" key="$fieldId" value="$fieldInfo">
                    <xen:if is="{$fieldInfo.viewable_message}">
                        <xen:if hascontent="true">
                            <dl class="pairsInline userField_{$fieldId}">
                                <dt>{xen:helper userFieldTitle, $fieldId}:</dt>
                                <dd><xen:contentcheck>{xen:helper userFieldValue, $fieldInfo, $user, {$user.customFields.{$fieldId}}}</xen:contentcheck></dd>
                            </dl>
                        </xen:if>
                    </xen:if>
                </xen:foreach>
       
            </xen:hook>
            </xen:if>

Then there's member_list_item which is called in XenStaff_index:

Code:
<xen:require css="xenforo_member_list_item.css" />
 
<li class="primaryContent memberListItem{xen:if $extended, ' extended'}"{xen:if $id, ' id="{$id}"'}>
 
    <xen:avatar user="$user" size="s" class="{xen:if $noOverlay, 'NoOverlay'}" />
 
    <xen:if is="{$extraTemplate}"><div class="extra">{xen:raw $extraTemplate}</div></xen:if>
 
    <div class="member">
 
        <xen:if is="{$user.user_id}">
 
            <h3 class="username"><xen:username user="$user" rich="true" class="StatusTooltip{xen:if $noOverlay, ' NoOverlay'}" title="{xen:string censor, $user.status}" /></h3>
     
            <div class="userInfo">
                <div class="userBlurb dimmed">{xen:helper userBlurb, $user}</div>
                <dl class="userStats pairsInline">
                    <dt title="{xen:phrase total_messages_posted_by_x, 'name={$user.username}'}">{xen:phrase messages}:</dt> <dd>{xen:number $user.message_count}</dd>
                    <dt title="{xen:phrase number_of_times_something_posted_by_x_has_been_liked, 'name={$user.username}'}">{xen:phrase likes_received}:</dt> <dd>{xen:number $user.like_count}</dd>
                    <dt>{xen:phrase trophy_points}:</dt> <dd title="{xen:phrase trophy_points}">{xen:number $user.trophy_points}</dd>
                </dl>
            </div>
     
        <xen:else />
            <h3 class="username guest dimmed">{xen:phrase guest}</h3>
        </xen:if>
 
        <xen:if hascontent="true">
            <div class="contentInfo"><xen:contentcheck>{xen:raw $contentTemplate}</xen:contentcheck></div>
        </xen:if>
 
    </div>
 
</li>

Any suggestions?
 

Attachments

  • Guild Members Page.webp
    Guild Members Page.webp
    10.3 KB · Views: 61
Hi Greg,

You can output the content of custom user fields using this:

{$user.customFields.fieldID}

Just replace fieldID with the ID of your custom user field.
 
Thanks, I seem to be able to get the "title", but not the value listed after it..

I.e. I can get Battle.net BattleTag: (but here the users value is not showing).

Can you post the exact code needed for member_list_info please?
 
Reminded of this:

http://xenforo.com/community/thread...message_user_info-template.20792/#post-314978

This is for the member list and not XenStaff, but in looking at the code I think the same problem applies.

Untested but...

library/XenStaff/ControllerPublic/Index.php

Add the red code:

Rich (BB code):
<?php

	class XenStaff_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
	{

		public function actionIndex()
		{

		$options = XenForo_Application::get('options');

		if (!$options->displaystaffActive)
		{
			return $this->responseError(new XenForo_Phrase('access_url_staff_off'));
		}


		$staffGroupsModel = $this->getModelFromCache('XenStaff_Model_StaffGroups');
		$staffGroupsUserIdsModel = $this->getModelFromCache('XenStaff_Model_StaffGroupsUserIds');
		$staffUserInfoModel = $this->getModelFromCache('XenForo_Model_User');
		$staffGroupsUniqueIdsModel = $this->getModelFromCache('XenStaff_Model_StaffGroupsUniqueIds');

		$staffGroups = $staffGroupsModel->getSelectedUserGroups();
		$staffGroupsUserIds = $staffGroupsUserIdsModel->getListofUsersPerStaffGroup();
		$staffIds = $staffGroupsUniqueIdsModel->getListofUniqueIds($staffGroupsUserIds);
		$staffUserInfo = $staffUserInfoModel->getUsersByIds($staffIds, $staffOptions = array('join' => XenForo_Model_User::FETCH_USER_FULL));

		$staffUserInfo = $staffUserInfoModel->prepareUserCards($staffUserInfo);

		$visitor = XenForo_Visitor::getInstance();


		if ((!$options->displaystafftoAll) AND !(in_array($visitor['user_id'], $staffIds)))
		{
			return $this->responseError(new XenForo_Phrase('access_url_staff_only'));
		}


		$onlineUsers = $this->getModelFromCache('XenForo_Model_Session')->getSessionActivityQuickList(
			$visitor->toArray(),
			array('cutOff' => array('>', $this->getModelFromCache('XenForo_Model_Session')->getOnlineStatusTimeout())),
			($visitor['user_id'] ? $visitor->toArray() : null)
		);

	        $staffOnline = array();

		if (!empty($onlineUsers))
                {
		        foreach ($onlineUsers['records'] AS $staffId)
		        {

		                if (in_array($staffId['user_id'], $staffIds))
                                {
                                       $staffOnline[] = $staffId;
                                }

		        }

		}

		$viewParams = array(
			'staffgroups' => $staffGroups,
			'staffgroupsuserids' => $staffGroupsUserIds,
			'staffuserinfo' => $staffUserInfo,
			'staffonline' => $staffOnline
		);

			return $this->responseView('XenStaff_ViewPublic_Index', 'XenStaff_index', $viewParams);

		}

	}

That should allow you to use this code inside of the member_list_item template:

Rich (BB code):
{$user.customFields.field_id}

Note that editing this template will affect both the member list and the XenStaff page since they both use the same template.
 
Oh, sorry no I didn't - I'm on my iPhone so I missed it. I'll give it a go. With that code in index.php, what other code do i need exactly to output title:user data, I.e. BattleTag: (users BattleTag) in XenStaff_Index - can you copy and paste the existing code and add it in red?

Is there an easy way to hide the title:output if the field has not been filled in as well?
 
Ideally just the staff page but if the members list must also change then I guess there's not much we can do.

Either way if you can write the code into my existing template (not sure which one?) in red, including the "hide if no data code"?
 
can you copy and paste the existing code and add it in red?

The entire contents of that file is posted. You can add just the red code or copy the entire contents.

Is there an easy way to hide the title:output if the field has not been filled in as well?

Use this in the template:

Rich (BB code):
<xen:if is="{$user.customFields.field_id}">
	TITLE HERE: {$user.customFields.field_id}
</xen:if>
 
Great, thanks. Since your first code was specific to the staff section, does that mean that I put that last code into XenStaff_Index or member_info_group (and then I'm assuming it will only work for the staff section anyways because the first code was specific to it?)
 
Great, thanks. Since your first code was specific to the staff section, does that mean that I put that last code into XenStaff_Index or member_info_group (and then I'm assuming it will only work for the staff section anyways because the first code was specific to it?)

This code:

Rich (BB code):
<xen:if is="{$user.customFields.field_id}">
	TITLE HERE: {$user.customFields.field_id}
</xen:if>

Goes in this template:

Admin CP -> Appearance -> Templates -> member_list_item
 
Is it possible to add custom user fields in page_container?

I'm trying to do this:
Code:
<link rel="stylesheet" type="text/css" href="{$user.customFields.user_css}" />

But it seems to not be able to retrieve the value.

EDIT: nevermind, solved using $visitor instead of $user.
 
Top Bottom