![]() |
|
|||||||
| vBulletin技术交流 主要讨论vBulletin的安装使用、模板风格、插件以及小技巧等。 |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
IP: 112.87.0.239
|
|||
|
|||
|
Template Conditionals
Template Conditionals are a powerful tool for controlling the XHTML output from your templates. They allow you to create simple if/else branches within your templates, in order to display different content depending on the condition you specify. For example you may want to show a different welcome message on the front page of your board to registered users and to guests. The way to know whether or not the person visiting a page is a guest, or a logged-in user is to check the value of $bbuserinfo[userid]. If the value is 0, the visitor is a guest (or not logged-in), otherwise the visitor is a registered member. This is a simple conditional to show a welcome message to guests only. Code:
<vb:if condition="$bbuserinfo['userid'] == 0">
<p>Welcome to the forum!<br />
If this is your first visit, we hope you enjoy your stay!</p>
</vb:if>
This example extends the previous conditional to show a different message to registered members from that shown to guests. Code:
<vb:if condition="$bbuserinfo['userid'] == 0">
<p>Welcome to the forum!<br />
If this is your first visit, we hope you enjoy your stay!</p>
<vb:else />
<p>Welcome back, $bbuserinfo[username].<br />
<a href="search.php?do=getnew">Click here to view new posts</a>.
</vb:if>
Code:
<vb:if condition="$my_variable == 1">
<p>My variable is equal to one.</p>
<vb:elseif condition="$my_variable == 2" />
<p>My variable is equal to two.</p>
<vb:else />
<p>My variable is equal to neither one nor two.</p>
</vb:if>
<vb:if condition="THIS_SCRIPT == 'index'"> <p>My variable is equal to one.</p> <vb:else /> <p>My variable is not equal to one.</p> </vb:if> <if condition="THIS_SCRIPT == 'index'"> </if> |
![]() |
| Currently Active Users Viewing This Thread: 2 (0 members and 2 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to Install an Zen Cart Template | topvip | ZenCart | 0 | 2009-08-23 05:35 PM |
| zen cart定制 zen cart二次开发 | car | ZenCart | 0 | 2009-08-21 01:11 AM |
| How do I create a new template in Vbulletin? | topvip | vBulletin技术交流 | 0 | 2009-07-12 12:54 PM |
| x-cart Template Editing Guide for 4.1.x | topvip | X-Cart | 0 | 2009-04-15 11:42 PM |
| Template Editing Guide for 4.1.x | topvip | X-Cart | 0 | 2009-03-10 08:12 AM |