XF 2.2 Looking for an <if> command for custom user field

DaveL

Well-known member
I've got a custom userfield, however if it's not filled out out shows the empty styling.
alliance.png

Looking for an <if> command to wrap the following in so the empty box doesn't show if this custom user field hasn't been completed.

Code:
<div style="background-color: blue; color: #FFF; padding: 2px; border: 2px solid #ff0000; border-radius: 5px 5px 5px 5px;">
    <center>{$user.Profile.custom_fields.AllianceName}</center>
</div>

Would really apprectiate any help.
 

Brogan

XenForo moderator
Staff member
XF code already does this by default.

How are you displaying the custom user field?

You just need to check the style property and have the field viewable in message user info.
 

DaveL

Well-known member
Thanks Brogan,

All my custom fields are enclosed in a drop down box in the message macros.

20.png

And then opened

10.png

I'm looking to display a custom userfield outside of this. So far i've managed to do that, but I can't style it, as the style always remains whether someone has completed that field or not. I was hoping there might be a conditional I can use such as 'If this custom user field has not been completed, do not display'.
Hope that makes sense!
 

DaveL

Well-known member
Try wrapping it in <xf:if contentcheck="true"> ... </xf:contentcheck>
Thanks @Brogan

If I try
Code:
<xf:if contentcheck="true">
<div style="background-color: blue; color: #FFF; padding: 2px; border: 2px solid #ff0000; border-radius: 5px 5px 5px 5px;">
    <center>{$user.Profile.custom_fields.AllianceName}</center>
</div></xf:contentcheck>

It comes back with the following error when I try to save
Template tags are not well formed. Tag contentcheck was found when expecting if. - Template modifications: public:message_macros
 

Brogan

XenForo moderator
Staff member
I pasted the wrong thing.

It should have been a closing if but there is also a second part of the content check.

Have a look in the message_macros template to see how it's used.
 

DaveL

Well-known member
I pasted the wrong thing.

It should have been a closing if but there is also a second part of the content check.

Have a look in the message_macros template to see how it's used.
Thanks, Think this is getting a bit beyond me.
Looked at the message_macros and the only content check I can see is
Code:
<xf:if contentcheck="true">
                <div class="message-userExtras">
                <xf:contentcheck>
                    <xf:if is="$extras.register_date">
                        <dl class="pairs pairs--justified">
                            <dt>{{ phrase('joined') }}</dt>
                            <dd>{{ date($user.register_date) }}</dd>
                        </dl>
                    </xf:if>

Having a guess, should mine look like:

Code:
<xf:if contentcheck="true">

<div style="background-color: blue; color: #FFF; padding: 2px; border: 2px solid #ff0000; border-radius: 5px 5px 5px 5px;">
<xf:contentcheck>
    <center><xf:if is="$user.Profile.custom_fields.AllianceName"></center>

</div>

</xf:if>
 
Last edited:

DaveL

Well-known member
Got it working :D

Code:
<xf:if contentcheck="true">
     <div style="background-color: blue; color: #FFF; padding: 2px; border: 2px solid #ff0000; border-radius: 5px 5px 5px 5px;">
        <center> <xf:contentcheck>{$user.Profile.custom_fields.AllianceName}</xf:contentcheck></center>
    </div>
</xf:if>
 
Top