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

XF 1.4 Inline conditional

Discussion in 'XenForo Questions and Support' started by RichardKYA, Aug 14, 2015.

  1. RichardKYA

    RichardKYA Well-Known Member

    Hello all,

    I'm trying to get this to work...

    Code:
    {xen:if '{$contentTemplate} != "forum_list" || {$contentTemplate} != "pagenode_container"', 'filter'}
    
    ...what am I doing wrong?

    Thank you kindly :)
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    What specifically is/isn't happening when using it?

    At first glance it looks ok to me from a syntax point of view.
     
  3. RichardKYA

    RichardKYA Well-Known Member

    Basically, it's just ignoring these conditions and applying the class anyway. The conditions work fine if I separate them and do them individually, but using the || doesn't seem to work :confused:
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Actually, the syntax does appear to be correct. I didn't really focus on the logic behind the statement.

    || is the same as saying OR

    != is the same as saying NOT EQUAL

    In that case, the logic says if the template is anything at all, apply the class, e.g:

    If the template IS forum_list then it is NOT EQUAL to pagenode_container therefore it will add the filter class.
    If the template is (as an example) thread_view then it is not equal to pagenode_container and it is not equal to forum_list therefore it will add the filter class.

    What exactly are you trying to do, I think you need to use slightly different logic to achieve it.
     
  5. RichardKYA

    RichardKYA Well-Known Member

    Of course, that makes perfect sense now that I think about it.

    I want the class to be added to all templates apart from the forum_list and page_container.

    How about something like...

    Code:
    {xen:if '{$contentTemplate} == "forum_list" || {$contentTemplate} == "pagenode_container"', '', 'filter'}
    
     
  6. RichardKYA

    RichardKYA Well-Known Member

    Hold on, wouldn't && solve my problems...

    Code:
    {xen:if '{$contentTemplate} != "forum_list" && {$contentTemplate} != "pagenode_container"', 'filter'}
    
    Lmao, stupid brain
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    That looks better to me :)
     
    RichardKYA likes this.
  8. Chris D

    Chris D XenForo Developer Staff Member

    Incidentally, another way is:

    Code:
    {xen:if '!in_array({$contentTemplate}, array("forum_list", "pagenode_container"))', 'filter'}
     
    RichardKYA likes this.
  9. RichardKYA

    RichardKYA Well-Known Member

    Awesome, I think I will use that way, as I also want to add help_index to the mix, plus I can easily add more if I need to.

    Thank you Chris, this is very helpful (y)
     
    Chris D likes this.

Share This Page