Announcement

Collapse
No announcement yet.

Looking for a specific conditional

Collapse
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Looking for a specific conditional

    Hello, I've been trying to implement a message that's shown beneath posts of my moderators, the only thing I have to figure out is the correct conditional that will apply this.
    My code is used in the
    Code:
    display_contenttype_threadview_header
    template, I tried using several variables such as $page, $conversation but after debugging them they don't have the 'usergroupid' strings in them, if that makes any sense.
    So basically all I wanted to do was create a conditional that will only allow specific usergroupid's to have a custom message under their posts that everyone else can see, not just them.
    Code:
    <vb:if condition="in_array($page['usergroupid'], array(1,2,3))">
    This code worked in a different template but not in the one that I mentioned above.
    I know in VB4 there was a "is_moderator" conditional or something to that effect, this would be exactly what I need here but I can't figure out to enable the conditional in the template.

    If anyone has a clue about this I would appreciate any help.
    Thank you.

    #2
    Try this:

    Code:
    <vb:if condition="$user->is_admin OR $user->is_supermod OR $user->is_moderator">
    Helpful? Donate. Thanks!
    Buy me a coffeePayPal QR Code
    Fast VPS Host for vBulletin:
    A2 Hosting & IONOS

    Comment


      #3
      You can also try

      Code:
      is_member_of(<userinfo>, <usergroupid>)
      but as you can see, you have to have a userinfo object which must contain userid, usergroupid and membergroupids fields. Usergroupid can be a single id or an array of ids.
      Helpful? Donate. Thanks!
      Buy me a coffeePayPal QR Code
      Fast VPS Host for vBulletin:
      A2 Hosting & IONOS

      Comment


        #4
        Originally posted by glennrocksvb View Post
        Try this:

        Code:
        <vb:if condition="$user->is_admin OR $user->is_supermod OR $user->is_moderator">
        Hey Glenn thank for helping out, unfortunately the code doesn't work.
        Here's an example for a conditional that would work if I needed it for userid's instead of usergroupid's.
        Code:
        <vb:if condition="$conversation['userid'] == 3">
        But again after debubbing $conversation it doesn't have the usergroupid string.

        Comment


          #5
          Can you debug $user object to check if it exists?

          Code:
          {vb:debugvardump user}
          Helpful? Donate. Thanks!
          Buy me a coffeePayPal QR Code
          Fast VPS Host for vBulletin:
          A2 Hosting & IONOS

          Comment


            #6
            Originally posted by glennrocksvb View Post
            Can you debug $user object to check if it exists?

            Code:
            {vb:debugvardump user}
            Yes it exists however if I use the $user object like this:
            Code:
            <vb:if condition="$user['usergroupid'] == 3">
            The code will only be viewed by users that belong to usergroup 3 and hidden to everyone else and what I need is to show the code to everyone but only have the code applied to people with the usergroup id 3, sounds a bit complicated but I don't know how to further explain it lol.
            TL;DR:
            Just as an example I wanted to give my moderators an emoji beneath their posts just above their signature, everyone else can see it but only moderators will have it.

            Comment


              #7
              So you need to check the usergroup of the author of the post. You cannot use $user object as it is the logged-in user's info not the author's. To get the author's usergroupid, you will need to call an API to get the userinfo passing the author's userid $conversation['userid']
              Helpful? Donate. Thanks!
              Buy me a coffeePayPal QR Code
              Fast VPS Host for vBulletin:
              A2 Hosting & IONOS

              Comment


                #8
                Try this:
                Code:
                {vb:data userInfo, user, fetchUserinfo, {vb:raw conversation.userid}}
                {vb:debugvardump userInfo}
                This may slow down the page as you'll call these up to 15 times for each post on a topic page even for the same user.
                Last edited by glennrocksvb; 03-08-2023, 10:05 PM.
                Helpful? Donate. Thanks!
                Buy me a coffeePayPal QR Code
                Fast VPS Host for vBulletin:
                A2 Hosting & IONOS

                Comment


                  #9
                  Originally posted by glennrocksvb View Post
                  This this:
                  Code:
                  {vb:data userInfo, user, fetchUserinfo, {vb:raw conversation.userid}}
                  {vb:debugvardump userInfo}
                  This may slow down the page as you'll call these up to 15 times for each post on a topic page even for the same user.
                  Thanks Glenn! that worked perfectly.
                  Is there anything I can change in order to avoid any delay caused by this but keep the same outcome? I don't feel any delay or pages slowing down but I'll take your word for it.
                  Your next coffee is on me by the way

                  Comment


                    #10
                    Not at the moment. It's good the delay is negligible or unnoticeable. Just observe when your site gets busier and bigger.
                    ​​​​​​Btw, thanks for the coffee!

                    jim carrey coffee GIF
                    Helpful? Donate. Thanks!
                    Buy me a coffeePayPal QR Code
                    Fast VPS Host for vBulletin:
                    A2 Hosting & IONOS

                    Comment

                    Users Viewing This Page

                    Collapse

                    There is 1 user viewing this forum topic.

                    • Guest Guest

                    Latest Posts

                    Collapse

                    Working...
                    X
                    Searching...Please wait.
                    An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

                    Please push the back button and reload the previous window.'
                    An unexpected error was returned: 'Your submission could not be processed because the token has expired.

                    Please push the back button and reload the previous window.'
                    An internal error has occurred and the module cannot be displayed.
                    There are no results that meet this criteria.
                    Search Result for "|||"