Announcement

Collapse
No announcement yet.

Using conditionals and vb code on CMS pages

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

  • [CMS] Using conditionals and vb code on CMS pages

    Hi there.

    I have some code on a page that I want to display only to certain usergroups and I also want to include their username if they can see it. How would I write this, and do I have to use a PHP or Static HTML content type in order to do it?

    This is what I can gather I should do... is it correct?...

    Code:
    <vb:if condition="is_member_of($bbuserinfo, 5,6,7)">
    
    
    <div>
    <p>Hello {vb:raw bbuserinfo.username},</p>
    
    
    <p>Stuff for admins is displayed here</p>
    </div>
    
    
    <vb:else />
    
    
    <p>I'm sorry. You are not authorized to view this page.</p>
    
    
    </vb:if>
    at the moment this is not working if I put the code in an HTML content page, so I'm not sure what's going wrong.

    Thanks for any help in advance!
    Last edited by princesspepper; Sat 10 Sep '11, 6:47am.

  • #2
    You can only use that code in a template so you would need to use php and have it reference a template instead.
    MARK.B | vBULLETIN SUPPORT

    TalkNewsUK - My vBulletin 5.6.3 Demo
    AdminAmmo - My Cloud Demo

    Comment


    • #3
      The above code won't work in content. It will only work in templates within the Admin CP. You would need to write custom PHP code in a direct evaluation page.
      Translations provided by Google.

      Wayne Luke
      The Rabid Badger - a vBulletin Cloud demonstration site.
      vBulletin 5 API

      Comment


      • #4
        So how would I go about doing that?

        Comment


        • #5
          Goto AdminCP>Styles and Templates>'Style Manager' select the template you use if you use multiple you need to make sure it exists in all styles else it will work on one template and not on the next. From the pulldown menu select 'Add New Template' give it a title and add code to it. Now make an Article that uses PHP and call the template you made in that article. If you need to know how to call a template look on vbulletin.org for examples press the tab Articles and you will find articles about templates.

          Comment


          • #6
            Thanks. I'll take a look

            Comment


            • #7
              I originally did what I needed to do with this issue by creating a custom page and linking to it as http://www.myforum.com/misc.php?do=page&template=MyPage because the mobile skin did not include CMS pages, but now it does, I really would like to include my template as a PHP evaluation page in the CMS as it will make a big difference to future upgrades.

              I have searched VB.org as suggested, but I either do not understand what the articles are saying or it's just not there, as I can't find anything about how to call a template into a PHP evaluation page in the CMS. I have searched high and low.

              Does anyone have a direct link to an article that will explain it please?

              Thanks in advance!

              Comment


              • #8
                Here is an article on how to render templates and register variables for use in those templates:

                http://www.vbulletin.org/forum/showthread.php?t=228078
                Translations provided by Google.

                Wayne Luke
                The Rabid Badger - a vBulletin Cloud demonstration site.
                vBulletin 5 API

                Comment


                • #9
                  Thanks. Well, that's me stuffed then. I've already read that article and it makes all but NO sense to me, and I'm not a php newbie!

                  All I want to do is call the contents of a template called custom_MyPage into the CMS content. I cannot understand why it has to be so hard to do that for a CMS.

                  How come you can't use the normal VBulletin variables and conditionals in a CMS page in the same way that you use smarty in other CMS systems? It seems that this would be a lot more logical and user friendly.

                  Comment


                  • #10
                    You can use normal variables. You can't use conditionals. Template Conditionals are simply wrappers for PHP's IF structures. When a template is saved, they are converted to the proper PHP code. Since user generated content is not parsed like templates the conditionals don't work.

                    If you want to test a condition in a direct evaluation page, you would simply us the PHP code to do so -

                    if ($variable == value) {
                    do something
                    } else {
                    do something else }

                    Your entire page should be in a PHP context. If a variable isn't available, you need to create an instance of the class and/or include the files that manage the class. At the very least you'll need to include global.php.
                    Translations provided by Google.

                    Wayne Luke
                    The Rabid Badger - a vBulletin Cloud demonstration site.
                    vBulletin 5 API

                    Comment


                    • #11
                      All I need the page to do is a) only display to certain usergroups and b) display their username. Not really rocket science stuff.

                      I know how to do it in VB pages, as in my first post example...

                      Code:
                      <vb:if condition="is_member_of($bbuserinfo, 5,6,7)"> 
                      
                        <div>  
                      <p>Hello {vb:raw bbuserinfo.username},</p>  
                      <p>Stuff  for admins is displayed here</p> 
                      </div> 
                      
                        <vb:else />  
                      
                      <div>
                      <p>I'm sorry. You are not authorized to view this page.</p>   
                      </div>
                      
                      </vb:if>
                      But how would I call these variables normally? What are they?

                      Code:
                      if ($usergroup == (5 || 6 || 7)) {
                      
                      echo "<div>  
                      <p>Hello " . $username . ",</p>  
                      <p>Stuff  for admins is displayed here</p> 
                      </div>";
                      };
                      else {
                      echo "<div>
                      <p>I'm sorry. You are not authorized to view this page.</p>   
                      </div>";
                      };
                      I need to know what the variables are for $username and $usergroup and then I'm away

                      Comment


                      • #12
                        PHP Code:
                        require_once(DIR '/global.php');
                        require_once(
                        DIR '/includes/functions.php');

                        if (
                        is_member_of($vbulletin->userinfo,5,6,7)) {
                            
                        do_stuff
                        } else {
                           
                        do_other_stuff

                        It is pretty basic PHP.

                        If you still want to use a template, just register the template and output it in your code, then your conditional will continue working. That is what the previous article shows.
                        Translations provided by Google.

                        Wayne Luke
                        The Rabid Badger - a vBulletin Cloud demonstration site.
                        vBulletin 5 API

                        Comment


                        • #13
                          Thanks. Somehow, that is far more easy to understand than the aritcle. Will have a go now.

                          Your time helping me is much appreciated

                          Comment


                          • #14
                            Just out of interest... are all variables found in global.php or functions.php then? I've never known where to look in the past. It may actually be easier writing stuff that way than using vb code....

                            Comment


                            • #15
                              No, all of the varibles are found all over the code and many of them may only be available in some cases.

                              Comment

                              Related Topics

                              Collapse

                              Working...
                              X