Announcement

Collapse
No announcement yet.

How can I use a raw variable in an if statement?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Forum] How can I use a raw variable in an if statement?

    I preregistered a variable and I would like to use it in an if statement in a template. For example:

    Code:
    <vb:if condition="{vb:raw $my_preregistered_variable}">
    
    content
    
    </vb:if>
    What is the correct way of doing this?

  • #2
    Code:
    <vb:if condition="$my_preregistered_variable">
    
    content
    
    </vb:if>
    MARK.B | vBULLETIN SUPPORT

    TalkNewsUK - My vBulletin 5.5.4 Demo
    AdminAmmo - My Cloud Demo

    Comment


    • #3
      If it's properly registered why not just output the contents in the template? I guess my question is, why the conditional?
      sigpic
      Nation of Blue - Kentucky Wildcats Sports


      Some CMS Goodness: Add Avatar to Article

      Comment


      • #4
        Originally posted by Mark.B View Post
        Code:
        <vb:if condition="$my_preregistered_variable">
        
        content
        
        </vb:if>
        Hi Mark,

        That doesn't work. Preregistered variable have to be in the form of: {vb:raw $my_preregistered_variable}
        Last edited by Andy; Fri 10th Feb '12, 3:40pm.

        Comment


        • #5
          Originally posted by reefland View Post
          If it's properly registered why not just output the contents in the template? I guess my question is, why the conditional?
          When a member has is on another members Ignore List, currently threads are show when viewing the forums. I would like to put a conditional around the threadbit template so that it's not displayed if the thread is started by a member that is on another members Ignore List.
          Last edited by Andy; Fri 10th Feb '12, 3:51pm.

          Comment


          • #6
            {vb:raw $variable} is correct. If you use it in a conditional, then it needs to meet some condition even if it is != "".
            sigpic
            Nation of Blue - Kentucky Wildcats Sports


            Some CMS Goodness: Add Avatar to Article

            Comment


            • #7
              Mark.B is correct, if you use it in a conditional it would be $my_preregistered_variable. You can use it without and comparison operator because it will be converted to a boolean based on a set of rules (see the php docs, http://us2.php.net/manual/en/languag...oolean.casting).

              To insert the value other places in the template it would be {vb:raw my_preregistered_variable} (no $).

              Comment


              • #8
                You are right, it is {vb:raw variable}.
                sigpic
                Nation of Blue - Kentucky Wildcats Sports


                Some CMS Goodness: Add Avatar to Article

                Comment


                • #9
                  The preregistered variable in my case is equal to the following:

                  $thread['postuserid'] <> '7460'

                  This works just fine to exclude threadid 7460 when viewing the forum it is in.

                  Code:
                  <vb:if condition="$thread['postuserid'] <> '7460'">
                  
                  threadbit template
                  
                  </vb:if>
                  However none of the following work.

                  Code:
                  <vb:if condition="{vb:raw $my_preregistered_variable}">
                  
                  threadbit template
                  
                  </vb:if>
                  Code:
                  <vb:if condition="$my_preregistered_variable">
                  
                  threadbit template
                  
                  </vb:if>

                  Comment


                  • #10
                    Originally posted by klh View Post

                    To insert the value other places in the template it would be {vb:raw my_preregistered_variable} (no $).
                    Hi KLH,

                    If I try it without the $ sign, I get the following error:

                    Warning: Invalid argument supplied for foreach() in [path]/includes/functions.php on line 3459

                    Comment


                    • #11
                      What does the code look like where you registered it?

                      Comment


                      • #12
                        Originally posted by klh View Post
                        What does the code look like where you registered it?
                        I preregister the variable using a plugin which calls a php script.

                        I can insert the preregistered variable in the first line of the threadbit template like this:

                        Code:
                        {vb:raw $my_preregistered_variable}
                        threabit template
                        This will echo the following many times as that threadbit is called many times when displaying a forum.

                        $thread['postuserid'] <> '7460'

                        Comment


                        • #13
                          I don't understand - are you just telling me it works with the '$'? OK, can't argue with the fact that it works for you. I just wondered what your preRegister line looks like because I've always seen it work without the dollar sign.

                          Comment


                          • #14
                            My plugin PHP code looks like this

                            Code:
                            ob_start();
                            include('/path/to/my/script.php');
                            $my_preregistered_variable = ob_get_contents();
                            ob_end_clean();
                            
                            vB_Template::preRegister('threadbit',array('my_preregistered_variable' => $my_preregistered_variable));

                            Comment


                            • #15
                              It appears there's no way to use a preregistered variable in an if statement.
                              Last edited by Andy; Fri 10th Feb '12, 4:55pm.

                              Comment

                              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                              Working...
                              X