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

Xen:If & Values

Discussion in 'XenForo Development Discussions' started by CFodder, Jan 18, 2011.

  1. CFodder

    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:

    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.
  2. Shadab

    Shadab Well-Known Member


    <xen:if is="{$cfisaplonker} > 0">
    CFodder likes this.
  3. CFodder

    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.
  4. Kier

    Kier XenForo Developer Staff Member

    Or, using the curly syntax,
    {xen:if '{$cfisaplonker} > 0', 'Test'}
  5. Brogan

    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?
    Boothby likes this.
  6. Kier

    Kier XenForo Developer Staff Member

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

    <p class="{xen:if $moo, 'moo', 'notMoo'}"> <!-- valid HTML -->
    <p class="<xen:if is="$moo">moo<xen:else />notMoo</xen:if>"> <!-- invalid HTML -->
    KiF, CNK, Boothby and 3 others like this.
  7. Mike

    Mike XenForo Developer Staff Member

    It's also shorter if you're doing something that's very simple. :)
  8. Jaxel

    Jaxel Well-Known Member

    can I do the following?
    {xen:if $checked == $forum.node_id, 'selected'}
    This is giving me a template error.
  9. Kier

    Kier XenForo Developer Staff Member

    The condition needs quotes and curlies if you're including more than just a simple variable check:
    {xen:if '{$checked} == {$forum.node_id}', 'selected'}
  10. Floris

    Floris Guest

    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.
    Fuhrmann likes this.
  11. xfrocks

    xfrocks Well-Known Member

    But you should use this for 'checked' and 'selected'

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

    {xen:checked '{$checked} == {$forum.node_id}'}
    Fuhrmann likes this.
  12. covort

    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.
  13. xfrocks

    xfrocks Well-Known Member

    Should be

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

    covort New Member


    Thanks a lot works a charm
  15. CNK

    CNK Active Member

    How i can use:
    {xen:if '{$options.2} == myString', 'some html code'}
  16. Nobita.Kun

    Nobita.Kun Well-Known Member

    Should be:
    {xen:if '{$options.2} == "myString"', 'some html code'}

Share This Page