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

XF 1.2 Custom Fields in userblurb

Discussion in 'Styling and Customization Questions' started by florencia, Mar 24, 2014.

  1. florencia

    florencia Active Member

    how do I add a custom field in the userblurb? I would like to have: forum title, full name (custom field), organization (custom field), occupation/job title (custom field), location.

    I removed the fields i don't want like gender in core.php, but how do I add the custom fields?

    /**
    * Helper, for the user blurb "Title, gender, age, from location".
    *
    * @param array $user
    * @param boolean Include user title in blurb
    *
    * @return string
    */
    public static function helperUserBlurb(array $user, $includeUserTitle = true)
    {
    if (!is_array($user) || empty($user['user_id']))
    {
    return '';
    }

    $parts = array();

    if ($includeUserTitle && $userTitle = self::callHelper('usertitle', array($user)))
    {
    $parts[] = '<span class="userTitle" itemprop="title">' . $userTitle . '</span>';
    }

    /**if (!empty($user['gender']))
    *{
    * $parts[] = new XenForo_Phrase($user['gender']);
    *}
    *
    *if (!isset($user['age']) && !empty($user['show_dob_year']) && !empty($user['dob_year']))
    *{
    * $user['age'] = self::_getModelFromCache('XenForo_Model_UserProfile')->getUserAge($user);
    *}
    *
    *if (!empty($user['age']))
    *{
    * $parts[] = $user['age'];
    *}
    */
    if (!empty($user['location']))
    {
    $user['locationCensored'] = XenForo_Helper_String::censorString($user['location']);

    $location = '<a href="'
    . XenForo_Link::buildPublicLink('misc/location-info', '', array('location' => $user['locationCensored']))
    . '" class="concealed" target="_blank" rel="nofollow">'
    . htmlspecialchars($user['locationCensored'])
    . '</a>';

    $parts[] = new XenForo_Phrase('from_x_location', array('location' => $location), false);
    }

    return implode(', ', $parts);
    }
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Where do you want the custom user fields to display?
     
  3. florencia

    florencia Active Member

    in the members list, members profile page, and on the left of threads in the user card box.

    Screen Shot 2014-03-24 at 12.16.53 PM.jpg


    Screen Shot 2014-03-24 at 3.06.50 PM.jpg

    Screen Shot 2014-03-24 at 3.08.10 PM.jpg
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    Custom user fields are already shown on profiles, under the Information tab.

    They can also be shown in the message user info block by enabling Style Properties -> Message Elements: Show custom user fields

    I haven't checked if the data is available in the member list. I suspect not so it will require custom development.
     
  5. florencia

    florencia Active Member

    The enabling Message Elements worked for the user card on the left of the threads but did not for the members list like you correctly suspected. I will see if I manage to work that one out. Thank you.
     
  6. florencia

    florencia Active Member

    How would you add the custom field to the core.php, I have tried {$user.customFields.field_id} but it doesn't work. I want to add a custom field to the Helper, for the user blurb "Title, gender, age, from location, custom field".
     
  7. Amaury

    Amaury Well-Known Member

    He did not say that option made them show on the member list.
     
  8. florencia

    florencia Active Member

    I know... thats why I said "like you correctly suspected." mmm? I don't understand what you are saying... please elaborate your conspiracy theory... LOL
     
  9. Amaury

    Amaury Well-Known Member

    If you knew, then you wouldn't have said that.

    I elaborated quite perfectly what I meant.

    But this isn't the place for this, so I digress.
     
  10. florencia

    florencia Active Member

    Maybe William Shakespeare here (Amaury) can let us get back to what really matters after a small distraction, I ask again...

    How would you add the custom field to the core.php? I have tried {$user.customFields.field_id} but it doesn't work. I want to add a custom field to the Helper, for the user blurb "Title, gender, age, from location, custom field".
     
  11. Martok

    Martok Well-Known Member

    To be, or not to be: that is the core.php.
    What's in a custom field? That which we call a rose, by any other custom field would smell as sweet.
    Now is the Helper of our discontent, made glorious summer by this sun of York.

    :D
     
    CaptainMorgan and Amaury like this.
  12. florencia

    florencia Active Member

Share This Page