Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

If I wanted to write a conditional for replacing a user's username with a custom field input within a specific node, how would one do that?

I have this, but I know it's wrong and the brain's gone foggy:

Code:
<xf:if is="{{$forum.node_id == 53 && $user.Profile.custom_fields.DDCharName}}"><xf:username user="$user.Profile.custom_fields.DDCharName" rich="true" defaultname="{$fallbackName}" itemprop="name" /><xf:else /><xf:username user="$user" rich="true" defaultname="{$fallbackName}" itemprop="name" /></xf:if>
 
I don't think this will work with <xf:username .. />. This template function takes a User object ($user in your code) and this has the user name included.

So, if you just want to display a user name as plain text, you could do something like:

HTML:
<xf:if is="$forum.node_id == 53 && $user.Profile.custom_fields.DDCharName">
[COLOR=rgb(224, 224, 224)]    $user.Profile.custom_fields.DDCharName
<xf:else />
   <!-- // your default code -->
</xf:if>

If you want more fancy stuff (like displaying an alternative user overlay), I think you will need to code an add-on.[/COLOR]
 
I don't think this will work with <xf:username .. />. This template function takes a User object ($user in your code) and this has the user name included.

So, if you just want to display a user name as plain text, you could do something like:

HTML:
<xf:if is="$forum.node_id == 53 && $user.Profile.custom_fields.DDCharName">
[COLOR=rgb(224, 224, 224)]    $user.Profile.custom_fields.DDCharName
<xf:else />
   <!-- // your default code -->
</xf:if>

If you want more fancy stuff (like displaying an alternative user overlay), I think you will need to code an add-on.[/COLOR]
Yeah, I assumed it would be something to do with that. I tried just the custom field, that doesn't work, either.
 
message_macro
o.k. so it's message_macros, so this part should work:

{{$user.Profile.custom_fields.DDCharName}}

but you won't have access to $forum. Try replacing that part with $xf.reply.contentKey == 'node-53'.

So, try this (untested):
HTML:
<xf:if is="$xf.reply.contentKey == 'node-53' && $user.Profile.custom_fields.DDCharName">
    {{$user.Profile.custom_fields.DDCharName}}
<xf:else />
   <!-- // your default code -->
</xf:if>
 
o.k. so it's message_macros, so this part should work:

{{$user.Profile.custom_fields.DDCharName}}

but you won't have access to $forum. Try replacing that part with $xf.reply.contentKey == 'node-53'.

So, try this (untested):
HTML:
<xf:if is="$xf.reply.contentKey == 'node-53' && $user.Profile.custom_fields.DDCharName">
    {{$user.Profile.custom_fields.DDCharName}}
<xf:else />
   <!-- // your default code -->
</xf:if>
That's still not doing it, sadly.
 
HTML:
<xf:if is="$xf.reply.containerKey == 'node-53' && $user.Profile.custom_fields.DDCharName">
    {{$user.Profile.custom_fields.DDCharName}}
<xf:else />
            <h4 class="message-name"><xf:username user="$user" rich="true" defaultname="{$fallbackName}" itemprop="{{ $includeMicrodata ? 'name' : '' }}" /></h4>
</xf:if>

There will be no link to the user profile though.
 
Back
Top Bottom