XF 2.0 Conditionals change?

NukeZero

Member
Not sure where to post this, if it's in the wrong place i apologize!

Anyways i'm trying to show X content per user post count in 2.0 beta 3 using a template conditional (message_macros) and i'm running into issues.

Old contionals used to be
Code:
<xen:if is="{$visitor.message_count} > x">
This content will show to members with more than x posts
</xen:if>

These no longer work so i tried some stuff and im not getting the result i expect.

Iv'e tried (always returns 1 even if the user has 4 posts):
Code:
<xf:if is="{$user.message_count} >= 1">
1
<xf:elseif is="{$user.message_count} >= 2" />
2
</xf:if>

And even:
Code:
<xf:if is="{$user.message_count|number} >= 1">
1
<xf:elseif is="{$user.message_count|number} >= 2" />
2
</xf:if>

What's the issue? Any help would be greatly appreciated.
 
Given this example:
Code:
<xen:if is="{$visitor.message_count} > x">
    This content will show to members with more than x posts
</xen:if>
The XF2 equivalent would be:
Code:
<xf:if is="$xf.visitor.message_count > x">
    This content will show to members with more than x posts
</xf:if>
 
And even:
Code:
<xf:if is="{$user.message_count|number} >= 1">
1
<xf:elseif is="{$user.message_count|number} >= 2" />
2
</xf:if>

What's the issue? Any help would be greatly appreciated.

Worth noting that with that the second one would never trigger since anything >= 2 would also be >= 1
 
Given this example:
Code:
<xen:if is="{$visitor.message_count} > x">
    This content will show to members with more than x posts
</xen:if>
The XF2 equivalent would be:
Code:
<xf:if is="$xf.visitor.message_count > x">
    This content will show to members with more than x posts
</xf:if>
This works, but how would it be written with an elseif because it doesn't seem to work with that?

Worth noting that with that the second one would never trigger since anything >= 2 would also be >= 1

Thanks for the help, both of you!
 
I am using this in a widget:

Code:
<xf:if is="{xen:helper ismemberof, $visitor, 3}">Show to admin  user group 3 only</xf:if>

According to the conditional guide and the example of how to change for version 2, I can't see what is wrong

But I get an error:

Oops! We ran into some problems.

Line 2: Expected valid expression.
 
xen:xxx stuff does not exist in XF 2 and you don't need a helper as $visitor is a user entity that can be used directly:

Code:
<xf:if is="$xf.visitor->isMemberOf(3)">Show to admin  user group 3 only</xf:if>
 
@Kirby in templates, methods are accessed using the dot-syntax like array elements.

So, it would be:

HTML:
<xf:if is="$xf.visitor.isMemberOf(3)">Show to admin  user group 3 only</xf:if>
 
-> does work as well (essentially compiles to the same code) and is necessary to access properties of objects that do not implement ArrayAccess.

But you are right, in this case it is not necessary and a . is sufficient.
 
Last edited:
Top Bottom