Custom Fields in message/message_user_info Template

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?
 
Rich (BB code):
<xen:if hascontent="true">
	{xen:helper userFieldTitle, my_identifier}:
	<xen:contentcheck>
		{xen:helper userFieldValue, $userFieldInfo.my_identifier, $user, {$user.customFields.my_identifier}}
	</xen:contentcheck>
</xen:if>
 
Rich (BB code):
<xen:if hascontent="true">
{xen:helper userFieldTitle, my_identifier}:
<xen:contentcheck>
{xen:helper userFieldValue, $userFieldInfo.my_identifier, $user, {$user.customFields.my_identifier}}
</xen:contentcheck>
</xen:if>

I don't get what does this code do ?
 
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].
 
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.
 
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
 
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:

Code:
{$choice} {$value}
 
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:

Code:
{$choice} {$value}

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.
 
Another example with my forum:

profile.webp

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

-JRW
 
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.

-JRW

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

library/XenForo/ControllerPublic/Member.php

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

Rich (BB code):
		$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:

Rich (BB code):
{$user.customFields.field_id}
 
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,

-JRW
 
Top Bottom