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

Checking if custom field is set to a value?

Right now I'm editing the XenForo templates to check to see if a user field is entered. It is a dropdown in "Preferences" with values correlating with 4 for Group A, 5 for Group B, etc. I'm using <xen if="{$user.customFields.a_field_in_preferences} == '4'">...</xen:if>, however {$user.customFields.fieldname} is usually blank. This is in relation to editing a template for the postbit section. Is there a separate variable I'm missing?

(Sorry if I'm making a lot of posts, still new to xenforo programming and everything.)

Jake Bunce

XenForo moderator
Staff member
Usually blank? Some users might not have a value entered for that field yet. Are you intending to have some default value for existing users?
The default value is blank, yes. I'm trying to do a template where if the field is set, display an image like:

<xen:if="{$user.customFields.preferenceField} == '4'">
<img src="/path/to/image.png" />
No matter what is picked for "preferenceField" for the user, the variable's value is always blank. What I'm wondering is if I have the wrong name of it, or whether you can't fetch custom personal details/contact info/preferences fields in postbit?