Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

What is the variable for custom user fields? in XF1 it was
{$visitor.customFields.fieldname}
 
And all the rest.

So our current Google ad targeting includes:

.setTargeting('page-type', ['{$xf.reply.template}'])
.setTargeting('club', ['{$xf.visitor.Profile.custom_fields.id of your custom field}'])
.setTargeting('forum', ['{$__globals.forum.node_id}'])
.setTargeting('forum-parent', ['{$parent_node_id}'])
.setTargeting('forum-thread-page', ['{$thread_id}/page-{$page_id}']) We had to do our own code to get these
.setTargeting('URL', [window.location.pathname]);
 
more Google Ad targeting:

googletag.pubads().setTargeting('ParentID', '{$forum.Node.parent_node_id}');
-----

<xf:if is="$forum.Node.parent_node_id == x">
code goes here
</xf:if>

<xf:if is="in_array({$forum.Node.parent_node_id}, [x,y,z])">
code goes here
</xf:if>
 
Is anyone successfully using xf:elseif statements? It's noted in the Resource description, but there are no examples and no one in the discussion has mentioned its use.

I'm getting errors when I try to implement.

The conditional statements can be expanded by using AND, OR conditional statements operators and using xf:if, xf:else, xf:elseif.
 
Hello everyone,
Quick question, what rule should I use if I want to show content in the Resources section but only in specific categories (let's say 3 and 5)
 
Is anyone successfully using xf:elseif statements? It's noted in the Resource description, but there are no examples and no one in the discussion has mentioned its use.

I'm getting errors when I try to implement.

The existing templates have examples. Here's one I pulled from a random template:

Code:
			<xf:if is="$alerts is not empty">
				<ol class="listPlain">
				<xf:foreach loop="$alerts" value="$alert">
					<li data-alert-id="{$alert.alert_id}"
						class="block-row block-row--separated{{ $alert.isUnviewed() ? ' block-row--highlighted' : ($alert.isRecentlyViewed() ? '' : ' block-row--alt') }}">
						<xf:macro template="alert_macros" name="row" arg-alert="{$alert}" />
					</li>
				</xf:foreach>
				</ol>
			<xf:elseif is="$page <= 1" />
				<div class="block-row">{{ phrase('you_do_not_have_any_recent_alerts') }}</div>
			<xf:else />
				<div class="block-row">{{ phrase('no_alerts_can_be_shown') }}</div>
			</xf:if>
 
If I upgrade from version 1.5 to 2.0 will the conditional statements I inserted into the templates disappear?
 
Is there a way to hide a button I've made if the person who created the thread (I don't mean person viewing the thread, the person who created the thread), is already part of usergroup X?
 
Is there a way to hide a button I've made if the person who created the thread (I don't mean person viewing the thread, the person who created the thread), is already part of usergroup X?

This should work with user group id (2 = Registered in this sample) and show a button if thread starter user is not in that user group.

Rich (BB code):
<xf:if is="!$thread.User.isMemberOf(2)">
    <xf:button href="{{ link('whats-new') }}" class="button--link">
        I am not in the Registered user group
    </xf:button>
</xf:if>
 
What conditional should I use to display content in a specific RM category? The example for forum categories doesn't work there.
 
Nice, thank you @smozgur

I accidentally stumbled onto this way... Is there a difference?

HTML:
<xf:if is="$resource.resource_category_id == 9">
               Show content..
</xf:if>
 
Nice, thank you @smozgur

I accidentally stumbled onto this way... Is there a difference?

HTML:
<xf:if is="$resource.resource_category_id == 9">
               Show content..
</xf:if>

Better actually. I was looking in the global template PAGE_CONTAINER (forgot to mention). It should be $resource in resource_view, and $category in resource_category templates. It changes according to context.
 
Back
Top Bottom