Xen:If & Values

CFodder

Well-known member
I've tried for the life of me, prob a simple syntax error, but I can't the if statement to work with a value. Have looked at other code to see if I can figure it but to no avail.

Am trying to get an item to display if the value is larger than zero, an example of what I'm trying tdo do is:

<xen:if {xen:number $cfisaplonker} != 0>
Have tried wrapping in brackets, quotes etc but it won't let me save it as coming up with a syntax error. Any help on this would be greatly appreciated.
 

CFodder

Well-known member
Brilliant ... thanks very much Shadab, my problem was I was leaving 'is' out, I thought that was only used when referencing usergroups, my bad.
 

Kier

XenForo developer
Staff member
Or, using the curly syntax,
Code:
{xen:if '{$cfisaplonker} > 0', 'Test'}
 

Brogan

XenForo moderator
Staff member
Out of interest, what's the difference between using Shadab's code with angular brackets and yours using curly brackets?
 

Kier

XenForo developer
Staff member
None, except that the curly syntax can be used inside tag attributes and maintain valid HTML:

HTML:
<p class="{xen:if $moo, 'moo', 'notMoo'}"> <!-- valid HTML -->


<p class="<xen:if is="$moo">moo<xen:else />notMoo</xen:if>"> <!-- invalid HTML -->
 

Jaxel

Well-known member
can I do the following?
Code:
{xen:if $checked == $forum.node_id, 'selected'}
This is giving me a template error.
 

Kier

XenForo developer
Staff member
can I do the following?
Code:
{xen:if $checked == $forum.node_id, 'selected'}
This is giving me a template error.
The condition needs quotes and curlies if you're including more than just a simple variable check:
Code:
{xen:if '{$checked} == {$forum.node_id}', 'selected'}
 
F

Floris

Guest
None, except that the curly syntax can be used inside tag attributes and maintain valid HTML:

HTML:
<p class="{xen:if $moo, 'moo', 'notMoo'}"> <!-- valid HTML -->
 
 
<p class="<xen:if is="$moo">moo<xen:else />notMoo</xen:if>"> <!-- invalid HTML -->
How come I never knew about this. Little gem. Or rather, perhaps I never realized this.
I remember having to fight a bit with tags where classes change, I will try to update those plugin templates.
 

xfrocks

Well-known member
can I do the following?
Code:
{xen:if $checked == $forum.node_id, 'selected'}
This is giving me a template error.
But you should use this for 'checked' and 'selected'

Code:
{xen:selected '{$checked} == {$forum.node_id}'}
Or

Code:
{xen:checked '{$checked} == {$forum.node_id}'}
 

covort

New member
<div class="{xen:if '{$news.thread_id%2}', 'primaryContentDark', 'primaryContent'}">

can any of you tell me if this is correct or point me in the direction i should be going.

basically i want if the news thread id is ODD use primarycontent dark, else use primary content.
 

xfrocks

Well-known member
<div class="{xen:if '{$news.thread_id%2}', 'primaryContentDark', 'primaryContent'}">

can any of you tell me if this is correct or point me in the direction i should be going.

basically i want if the news thread id is ODD use primarycontent dark, else use primary content.
Should be

Code:
{xen:if '{$news.thread_id} % 2 == 1', 'primaryContentDark', 'primaryContent'}
 

CNK

Active member
How i can use:
Code:
{xen:if '{$options.2} == myString', 'some html code'}
?
 
Top