XF 1.1 Help! Help! I need an adult! - Outputting Custom Fields

Castile

Member
I did some research and to call a custom field, you need to have the {$user.customFields.fieldID} parameter, but when I put it into the code (such as below, my fieldid is firstname). It outputs only.

| Castile, not Alex | Castile. Help?

<xen:if is="{$user.user_id}">
<a href="{xen:link members, $user}"
class="username{xen:if '!{$user.visible}', ' invisible'}{xen:if {$user.followed}, ' followed'}">{$user.customFields.firstname} | {$user.username}</a><xen:if is="{$i} < {$onlineUsers.limit}">,</xen:if>
<xen:else />
 

Jake Bunce

XenForo moderator
Staff member
The custom fields are not prepared in that list. A small code edit is required:

library/XenForo/Model/Session.php

Add the red code:

Rich (BB code):
	public function getSessionActivityQuickList(array $viewingUser, array $conditions = array(), array $forceInclude = null)
	{
		$fetchOptions = array(
			'join' => self::FETCH_USER,
			'order' => 'view_date'
		);
		$conditions['getInvisible'] = true; // filtered out if needed, but included in count
		$conditions['getUnconfirmed'] = true; // also filtered out but included in count

		$records = $this->getSessionActivityRecords($conditions, $fetchOptions);

		$records = $this->getModelFromCache('XenForo_Model_User')->prepareUserCards($records);

		$canBypassUserPrivacy = $this->getModelFromCache('XenForo_Model_User')->canBypassUserPrivacy();

		$forceIncludeUserId = ($forceInclude ? $forceInclude['user_id'] : 0);

		if (!empty($viewingUser['following']))
		{
			$following = explode(',', $viewingUser['following']);
		}
		else
		{
			$following = array();
		}
Now that template code will work.
 

Castile

Member
Will that allow me to use the custom fields for everything? Or just that template? I have to change a ton of other templates to facilitate that change across the board.
 

Jake Bunce

XenForo moderator
Staff member

Castile

Member
Would a plugin be a better option? Because in this case a lot of changes would have to be made, and should you guys update it in the future its going to be a nightmare for me.
 

Jake Bunce

XenForo moderator
Staff member
Would a plugin be a better option? Because in this case a lot of changes would have to be made, and should you guys update it in the future its going to be a nightmare for me.
Yes an addon would be better. That way the code changes aren't overwritten during an upgrade. But it might not be that many code changes. It depends on where you want the custom fields. In many areas the fields are already prepared.
 

Castile

Member
I primarily want it everywhere, the only place it probably would not matter is on the sidebar that tells you who you are.
 
Top