1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'XenForo Questions and Support' started by Castile, Aug 26, 2012.

  1. Castile

    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?

  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    In which template?
  3. Castile

    Castile Member

    Hi Jake,

    Its the sidebar_online_users template.
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

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


    Add the red 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']);
    			$following = array();
    Now that template code will work.
  5. Castile

    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.
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Just that template.

    Here is a similar code edit for the member list you might want:


    But other places like posts and user cards already have the fields prepared.
  7. Castile

    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.
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    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.
  9. Castile

    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.

Share This Page