• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Xen:If & Values

CFodder

Well-known member
#1
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
#3
Brilliant ... thanks very much Shadab, my problem was I was leaving 'is' out, I thought that was only used when referencing usergroups, my bad.
 

Brogan

XenForo moderator
Staff member
#5
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
#6
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
#8
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
#9
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
#10
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
#11
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}'}
 
#12
<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
#13
<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'}