Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

ehd

Well-known member
Great!

Should this:


6. How can I show different content to members and guests?

Code:
<xf:if is="!$xf.visitor.user_id">
Show only members
<xf:else />
Show only guests
</xf:if>


not be:

6. How can I show different content to members and guests?

Code:
<xf:if is="$xf.visitor.user_id">
Show only members
<xf:else />
Show only guests
</xf:if>

?

The "!" could be too much?
 

Alan_SP

Active member
To the best of my knowledge this should work; i don't see a reason why it wouldn't.. 🤔
This is error I get:
Line 28: Found a contentcheck tag without a contentcheck-based if tag. - Template modifications: public:message_macros
And I used it like this for example I mentioned:
HTML:
$0

                    <xf:if is="$xf.visitor.is_admin OR $xf.visitor.is_moderator">
                    <dl class="pairs pairs--justified">
                        <dt>{{ phrase('last_seen') }}</dt>
                        <dd dir="auto">
                            <xf:contentcheck><xf:useractivity user="$user" class="pairs--plainLabel" /></xf:contentcheck>
                        </dd>
                    </dl>
                    </xf:if>
 

nocte

Well-known member
The error message says all ;)

You can try adding 2 lines:


HTML:
$0

                    <xf:if is="$xf.visitor.is_admin OR $xf.visitor.is_moderator">
<xf:if contentcheck="true">
                    <dl class="pairs pairs--justified">
                        <dt>{{ phrase('last_seen') }}</dt>
                        <dd dir="auto">
                            <xf:contentcheck><xf:useractivity user="$user" class="pairs--plainLabel" /></xf:contentcheck>
                        </dd>
                    </dl>
</xf:if>
                    </xf:if>
 

Dragonfruit

Well-known member
Hi, how would you handle an apostrophe when writing an if conditional statement, example, if the data was "Jack's iPhone", that apostrophe would conflict with the statement:< xf:if is="{$xf.visitor.Profile.custom_fields.PhoneName} == 'Jack's iPhone'">

Just wondering how to correctly fix this.
 

nicodak

Well-known member
Did you try <xf:if is="{$xf.visitor.Profile.custom_fields.PhoneName} == 'Jack\'s iPhone'"> ?
It's really random... no certainty on that.
 

Dragonfruit

Well-known member
Did you try <xf:if is="{$xf.visitor.Profile.custom_fields.PhoneName} == 'Jack\'s iPhone'"> ?
It's really random... no certainty on that.

I just tried that, unfortunately it didn't work, I originally tried putting a back slash before and after it.
 

nocte

Well-known member
Try this:

HTML:
<xf:set var="$var" value="Jack's iPhone" />
<xf:if is="{$xf.visitor.Profile.custom_fields.PhoneName} == $var">

untested, but may work.
 
Top