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

XF 1.2 Conditional Statement issue

Discussion in 'XenForo Questions and Support' started by Moddis, Dec 8, 2013.

  1. Moddis

    Moddis Active Member

    I am using the beautiful resource on conditional Statements but ran into an issue with combining one of them:

    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 20 OR {$post.position} == 0">
    TEXT
    </xen:if>

    Ideally that should show me the TEXT in the first post of every page of a thread. 20 is the correct number of post that i have set up per thread page so it should work. is there another variable I am missing?

    Thanks!
     
    Last edited: Dec 8, 2013
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    What is the current functionality of what you are using? And if you want it to show after the first post, you should be doing == 0.
     
  3. Moddis

    Moddis Active Member


    The second part of the statement does have the 0 criteria so it shows up correctly in the first post of the thread. However, if does not show up as the first post (actually the 21st) of the same thread on page 2.

    BTW, I entered the incorrect quote so I updated the original thread with instruction on how it says to "How can I show content after post x on every page in a thread or conversation?"

    Thanks!

     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    You will need to duplicate it for $message.message_id. Try this:
    Code:
    <xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 1 OR {$message.message_id} % {$xenOptions.messagesPerPage} == 1">
    Text
    </xen:if>
    
     
    Moddis likes this.
  5. Moddis

    Moddis Active Member

    Thanks it worked perfectly except I changed the first "1" to a "0" and it did show up at the first post of each page.
     
  6. Moddis

    Moddis Active Member

    Oops, I also just realized I could have just used the "<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0">" without combining it without OR statement and it worked as well. The thing I was doing wrong is putting a 20 instead of a 0 like in your example.

    Thanks for the quick help!
     
  7. Moddis

    Moddis Active Member

    This is a little bit different of an issue but is an additional that I would like to add to the conditional statement.

    Is there something that would Not show to "TEXT" if the post author is part of user group x?
     
  8. Jeremy

    Jeremy XenForo Moderator Staff Member

    Yes. Paul's resource explains how to use ismemberof.

    How can I hide content from a specific user group?
    <xen:if is="!{xen:helper ismemberof, $visitor, x}">
    This content will be hidden from members of user group x
    </xen:if>
     
    Moddis likes this.
  9. Moddis

    Moddis Active Member

    I looked at that one but im trying to figure out if i can tweak it to, not hide content FROM a specific user group but hide content if the actual post is made by a specific user group.

    Paul's instructions say that $visitor is always the record for the current logged in user and $user is the record being processed(e.g message author). So using that, I guess i will try to transform your suggestion from $visitor to $user and see if its as simple as that to make it work:

    <xen:if is="!{xen:helper ismemberof, $user, x}">
    TEXT
    </xen:if>
     
  10. Jeremy

    Jeremy XenForo Moderator Staff Member

    I know that will work for Posts. Not entirely sure about conversations. I don't know why it wouldn't.
     
  11. Moddis

    Moddis Active Member

    (I replaced x with the user group id number)

    The above is not working and its giving me a bunch of errors on top of page:

    Code:
    Template Errors: thread_view
    Argument 1 passed to XenForo_Template_Helper_Core::helperIsMemberOf() must be of the type array, null given in
    
    Argument 1 passed to XenForo_Model_User::isMemberOfUserGroup() must be of the type array, null given, called in
    
    Argument 1 passed to XenForo_Template_Helper_Core::helperIsMemberOf() must be of the type array, null given in
    
    Argument 1 passed to XenForo_Model_User::isMemberOfUserGroup() must be of the type array, null given, called in
    
    .....
    This is not super important because I dont plan on using it this way for a long time but if there is anything else you think can be tried, please do let me know.
     
  12. Jeremy

    Jeremy XenForo Moderator Staff Member

    $user doesn't exist in this context. What template were you using this conditional in?
     
  13. Moddis

    Moddis Active Member

    I'm using it in the "ad_message_body" template.

    Again, to be clear, I would like to display "This Text" to all users and in every posts except if that post was made by usergroup 11.
     
  14. Jeremy

    Jeremy XenForo Moderator Staff Member

    Attempt using $message instead of $user.
     
    Moddis likes this.
  15. Moddis

    Moddis Active Member

    Awesome!! It worked:)
     
  16. Moddis

    Moddis Active Member

    Back with another question about this conditional:

    It is added to the "ad_message_below" template and it works great for showing the content under the first post of every thread/page. However, its is showing the same content under every single conversation message if I set the x to 0. If i set x to 1, it does not show the content at all.
     
  17. Jeremy

    Jeremy XenForo Moderator Staff Member

    Do you want to restrict it from showing in the conversation view?
     
  18. Moddis

    Moddis Active Member

    I would like to also show in conversation view but also just in the first message and not all of them.

    I know I can use this to restrict it completely to the first post but is there something specific that would help me identify the first message of a conversation (maybe <<xen:if is="{$message.conversation_id} == 0 "> ?)
     
  19. Jeremy

    Jeremy XenForo Moderator Staff Member

    This one should function:
     
  20. Moddis

    Moddis Active Member

    Unfortunately that does not work. It just meets the first criteria and still shows it in every conversation message. Also tried to test by deleting the first part (before the Or) but the second part did not have any affect and did not show content anywhere in conversation.
     

Share This Page