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

Understanding this {xen:if} statement.

Discussion in 'General PHP and MySQL Discussions' started by TheBigK, Feb 16, 2015.

  1. TheBigK

    TheBigK Well-Known Member

    In Kier's ScratchPad Addon, the template scratchpad_index has this line -

    HTML:
    <div id="ScratchpadNoNotes" class="secondaryContent {xen:if '{$notes}', 'hasNotes'}">There are no notes yet.</div>
    I'm wondering what exactly is {xen:if '{$notes}', 'hasNotes'} doing?

    My Guess: It's inserting class as 'hasNotes' if there are no notes.

    Am I right?
     
  2. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    {xen:if ...} is the same as PHP's short-hand conditional statement: http://davidwalsh.name/php-ternary-examples

    Code:
    {xen:if [condition], [what to add if the condition is true], [what to add if the condition is false]}
    
     
  3. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    And you can keep the false part empty if you don't need it ;)
    Code:
    {xen:if [condition], [what to add if the condition is true]}
    
     
    TheBigK likes this.
  4. Brogan

    Brogan XenForo Moderator Staff Member

    In the case of that example, it's adding the CSS class hasNotes to the div, if the $notes variable is true.
     
  5. TheBigK

    TheBigK Well-Known Member

    Okay, what if I only want to insert the false condition?

    Well, this is what the related CSS says -

    #ScratchpadNoNotes.hasNotes
    {
    display: none;
    }

    So, what if $notes is false?
     
  6. Brogan

    Brogan XenForo Moderator Staff Member

    If $notes is false, the hasNotes class won't be applied to the div.
     
  7. Mr. Goodie2Shoes

    Mr. Goodie2Shoes Well-Known Member

    Code:
    {xen:if ![condition], [what to add if the condition is false]}
    
    like for the example above:
    Code:
    {xen:if '!{$notes}', 'hasNotes'}
    
     
    TheBigK likes this.
  8. TheBigK

    TheBigK Well-Known Member

    Oh okay! I thought it'd break syntax. If it's false, the output will be rendered only using "secondaryContent". Cool stuff!
     

Share This Page