XF 2.3 Add link to custom field in message user info

Mr Lucky

Well-known member
Licensed customer
Currently if you tick Viewable in message user info on a custom field, then the expected behaviour is that it shows the entire contents of that user field. What I want do do is (for certain user fields that my include a long list of items) just show the title of the user field as a link to the actual field in the user's profile.

Can anyone please give me details on how to set about doing this?

Thanks

[EDIT} I just realised this may be way beyond a simple customisation I would be able to do, not least because custom fields showing in user profiles don't have anchor links
 
What you can do is create a template modification on custom_fields_macros to intercept how specific fields render in the message user info area. The custom fields there are output inside <dl> tags with data-field="your_field_id", which makes targeting them straightforward.
The tricky part you noticed is real — profile tabs don't have anchors for individual fields. But you can link to the About tab directly with {{ link('members', $user) }}#about, which gets close enough.
For a quick CSS-only approach that hides the value and keeps the title, add this to extra.less:
Code:
.message-userExtras dl[data-field="your_field_id"] dd {
    display: none;
}
But if you want the title to actually be a clickable link to the profile, you need a template modification on custom_fields_macros. Find where it outputs the <dt> for the field and wrap it for your specific field ID:
Code:
<xf:if is="$fieldId == 'your_field_id'">
    <dl class="{$valueClass}" data-field="{$fieldId}">
        <dt><a href="{{ link('members', $user) }}#about">{$fieldDefinition.title}</a></dt>
    </dl>
<xf:else />
One caveat: make sure $user is available in context where this macro is called. In the message user info context it should be, since it's passed from message_macros.
 
Back
Top Bottom