Announcement

Collapse
No announcement yet.

Using conditionals and vb code on CMS pages

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

  • princesspepper
    replied
    Ok. Thanks. I'll look there first then, and ask if I can't find stuff.

    Leave a comment:

  • Zachery
    Former vBulletin Support

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

    Leave a comment:

  • princesspepper
    Member

  • princesspepper
    replied
    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....

    Leave a comment:

  • princesspepper
    Member

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

    Your time helping me is much appreciated

    Leave a comment:

  • Wayne Luke
    vBulletin Technical Support Lead

  • Wayne Luke
    replied
    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.

    Leave a comment:

  • princesspepper
    Member

  • princesspepper
    replied
    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 ([B]$usergroup[/B] == (5 || 6 || 7)) {
    
    echo "<div>  
    <p>Hello " . [B]$username[/B] . ",</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

    Leave a comment:

  • Wayne Luke
    vBulletin Technical Support Lead

  • Wayne Luke
    replied
    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.

    Leave a comment:

  • princesspepper
    Member

  • princesspepper
    replied
    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.

    Leave a comment:

  • Wayne Luke
    vBulletin Technical Support Lead

  • Wayne Luke
    replied
    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

    Leave a comment:

  • princesspepper
    Member

  • princesspepper
    replied
    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!

    Leave a comment:

  • princesspepper
    Member

  • princesspepper
    replied
    Thanks. I'll take a look

    Leave a comment:

  • we_are_borg
    Senior Member

  • we_are_borg
    replied
    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.

    Leave a comment:

  • princesspepper
    Member

  • princesspepper
    replied
    So how would I go about doing that?

    Leave a comment:

  • Wayne Luke
    vBulletin Technical Support Lead

  • Wayne Luke
    replied
    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.

    Leave a comment:

  • Mark.B
    vBulletin Support

  • Mark.B
    replied
    You can only use that code in a template so you would need to use php and have it reference a template instead.

    Leave a comment:

Related Topics

Collapse

Working...
X