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

Custom Fields in message/message_user_info Template

Discussion in 'Styling and Customization Questions' started by Michael, Oct 5, 2011.

  1. Michael

    Michael Active Member

    I want to use the data from one of my custom fields in the message template, for example my custom field identifier is my_identifier, what is the code I would need to show the output of the my_indentifier field in the message template?

    Thank you :)

    Edit: I am aware that I can use the options but what do I use if I want it in the message template and only to pull one of them?
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    In the message template:

    Or in message_user_info:

    Michael likes this.
  3. Michael

    Michael Active Member

    Excellent thanks Jake as always :)
  4. Michael

    Michael Active Member

    Do you happen to know the if such and such a field is filled in conditional to wrap them in too? :D
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    <xen:if is="{$user.customFields.my_identifier}">
    Michael likes this.
  6. Michael

    Michael Active Member

    Thanks again! :D
  7. Kier

    Kier XenForo Developer Staff Member

    <xen:if hascontent="true">
    	{xen:helper userFieldTitle, my_identifier}:
    		{xen:helper userFieldValue, $userFieldInfo.my_identifier, $user, {$user.customFields.my_identifier}}
    Michael likes this.
  8. Kier

    Kier XenForo Developer Staff Member

    The above will give you the fully phrased version of the value and title.
    Michael likes this.
  9. Michael

    Michael Active Member

    Thank you, I know many others will need this :)
  10. account8226

    account8226 Guest

    I don't get what does this code do ?
  11. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  12. x7iBiT

    x7iBiT Member

    If for example my_identifier has a [value, text] format (radio buttons, drop down selection, etc.), how I can access them [value, text] independently of each other?

    If I put {$choice} in the 'Value Display HTML' field I can access to the [value] with the {xen:helper userFieldValue, $userFieldInfo.my_identifier, $user, {$user.customFields.my_identifier}}, but then I can't access to the [text].
  13. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I don't see any way to access the text values in those templates. Those text values are normally only used for editing the field in your profile. The actual value is what is displayed in posts.
    x7iBiT likes this.
  14. x7iBiT

    x7iBiT Member

    Thanks Jake. I found the way:
    • {$user.customFields.my_identifier} -> Give the VALUE (A-Z, 0-9, and _ only)
    • {xen:helper userFieldValue, $userFieldsInfo.my_identifier, $user, {$user.customFields.my_identifier}} -> Give the TEXT (or the HTML code given by the 'Value Display HTML' field)

    PD: The Kier's code have little bug (very very small, but enough to not work):
    it is $userFieldsInfo.my_identifier
    and not $userFieldInfo.my_identifier
    Saman Ice likes this.
  15. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    I also discovered that the text value can be used for display purposes if you setup some display HTML:

    Admin CP -> Users -> Custom User Fields -> [click the field] -> General Options -> Value Display HTML

    You can use these variables to access either the text or value for display:

    {$choice} {$value}
  16. x7iBiT

    x7iBiT Member

    I know. The problem is that when using a single field to save two things, and can be accessed separately and not simultaneously. For example, you can use the {$choice} to save a number, and the {$value} to save his associated name. If in the template code you put the number at the beginning, and the name at the end there is no way to do this using the Value Display HTML.

    The solution is using {$user.customFields.my_identifier} to access the number.
  17. x7iBiT

    x7iBiT Member

    Another example with my forum:


    Notice on the football (soccer) team name, and its badge (image). Instead of using two fields, is much more elegant to use one of type '{$choice} {$value}', as both are inter-related data. The problem is that between the name and badge there are several elements, so you need to access each data separately and not simultaneously.
  18. JRW-910

    JRW-910 Member

    I must really be missing something here. For some reason this code works in some templates and not in others.

    In the member_list_item template, I can get the title out of a custom field using the above code ({xen:helper userFieldTitle, my_identifier}), but I can't get the Value or Text out with ({xen:helper userFieldValue, $userFieldInfo.my_identifier, $user, {$user.customFields.my_identifier}}). Whats the deal?

    Both bits of code worked in other templates.

  19. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    The custom fields are not prepared for the member list. But you can edit this file to prepare them:


    Add the red code inside of the actionIndex() function:

    		$criteria = array(
    			'user_state' => 'valid',
    			'is_banned' => 0
    		// users for the member list
    		$users = $userModel->getUsers($criteria, array(
    			'join' => XenForo_Model_User::FETCH_USER_FULL,
    			'perPage' => $usersPerPage,
    			'page' => $page
    		$users = $userModel->prepareUserCards($users);
    		// most recent registrations
    		$latestUsers = $userModel->getLatestUsers($criteria, array('limit' => 8));
    		// most active users (highest post count)
    		$activeUsers = $userModel->getMostActiveUsers($criteria, array('limit' => 12));
    That will allow you to use this code inside of the member_list_item template:

    Eagle likes this.
  20. JRW-910

    JRW-910 Member

    You are the man! Worked perfectly.

    These custom user fields are so amazing and can really be used to customize a site unlike anything else... not sure why they were designed to only be used in certain places.

    Thanks so much,


Share This Page