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

Help with xen:if coding in template

Discussion in 'Styling and Customization Questions' started by bashy, May 10, 2012.

  1. bashy

    bashy Member

    Hi,

    I'm working on the userpanel template files and wanted to do something nice with the alerts you get.
    So I've got the code nearly done but I need to add different CSS classes depending on if the user has an unread alert or not.

    Here is a part of the code I used from the default template on XenForo;
    Code:
    <a href="{xen:link account/alerts}" class="{xen:if {$visitor.alerts_unread}, '', 'noalert'}">
      {xen:number $visitor.alerts_unread}
    </a>
    So that would spit out the class "noalert" if unread is empty.
    I want to add another class for if the user has an alert but I don't know the xen code enough to do it. I can do it fine in PHP :p

    PHP:
    if($visitoralerts_unread != '0') {
    echo 
    'alert';
    }
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You already have the conditional structure there. It's an "if else" logic. If true then value, else next value.

    Code:
    <a href="{xen:link account/alerts}" class="{xen:if {$visitor.alerts_unread}, 'alert', 'noalert'}">
      {xen:number $visitor.alerts_unread}
    </a>
    
     
    bashy likes this.
  3. bashy

    bashy Member

    Oh! I think I got confused at what , ' ', ' ' was doing :p
    Many thanks!

    What I got now :)
    [​IMG]

    Is there a guide to all of these xen codes? Also a list of variables available?
     

Share This Page