Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > Programming Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Template Editing - All the variables and coding bits you need to know!
toolblast's Avatar
toolblast
Join Date: Mar 2004
Posts: 266

I create innovative media and design

Show Printable Version Email this Page Subscription
toolblast toolblast is offline 04-18-2006, 10:00 PM

TEMPLATE EDITING, USEFUL VARIABLES, AND CODE SNIPPETS

Hi everyone,

While doing a hunt on vb.org for a list of the main vbulletin variables that I would need to output certain values in custom templates I was making, my search resulted in a huge lack of information so I decided to put together a list that will hopefully help any vbulletin coding beginner that wants to create a custom template and output certain information:

EDITING TEMPLATES
To begin to understand what these variables and code snippets are for, you first need to know how to edit a template in the first place. It is very easy and VBulletin makes it as simple as possible to do so. Here are a few tips to get you started:

1) Login to your ADMINCP (www.yoursite.com/admincp)
2) Click STYLES & TEMPLATES on the left
3) Click STYLE MANAGER

You are now seeing a list of all of the styles/themes you have on your vbulletin forum. By default you'll have "Default Style" which is VBulletin's style that comes with the out-of-box system.

4) Click the "ALL STYLES OPTION" dropdown. You will now see a list of options you can do to your default style. A few to note are:

- Edit Templates
- Add New Template
- Add Child Style
- Delete Style

5) We are going to click on EDIT TEMPLATES and then click the GO button (if the page has not refreshed already to the edit templates area).

You will now see a list of templates and headers with a scroll bar to scroll through them all. A few templates and headers to note are:

- footer
- Forum Display Templates
- Forum Home Templates
- header
- Navigation / Breadcrumb Templates

These will be the ones you will edit most commonly. To edit a template, simply double click on its name. If you double-click on a blue header, it will dropdown the sub-templates that are under that header. For example, "Forum Home Templates", when double-clicked, will show "FORUMHOME" as a sub-template under that header.

For this tutorial we are going to just focus on the "header" template. So go ahead and double click it to begin.


USEFUL VARIABLES

Ok, so lets go over some very useful variables that you can use in your templates. Once you have opened the "header" template in the previous step, try typing in some of these variables to see what they output in your forum:

1. $vboptions[bburl] - This variable outputs the url to your forum which you have set in your VBulletin general options. This is useful to use this instead of hardcoding in your website URL because in the future you may want to change your domain and don't want to have to search through your dozens of templates for where you hardcoded in the domain at the beginning.

2. $vboptions[bbtitle] - Outputs the title of your forum which is set in the general VBulletion options.

3. $bbuserinfo[username] - Very useful, this variable will output the username/nickname of the user currently logged in.

4. $headinclude - Used to output the header template

5. $vboptions[bburl]/usercp.php$session[sessionurl_q] - Useful url which will link to the USERCP for the user

6. $vboptions[bburl]/login.php?$session[sessionurl]do=logout&u=$bbuserinfo[userid] - Useful url which will log off the user when clicked

7. <phrase 1="$pmbox[lastvisitdate]" 2="$pmbox[lastvisittime]">$vbphrase[last_visited_x_at_y]</phrase> - This will show the last time the user logged into the forum. For example: You last visited: Today at 07:57 PM

8. $vboptions[bburl]/private.php? - URL to load the user's PM mailbox

9. $bbuserinfo[pmunread] - Will output how many unread PM's the user has

10. $bbuserinfo['field#'] - Will output the data that the user inputted for their user profile field which you can set up. Replace # with the number of the input field you want to display

11. $bbuserinfo['posts'] - Shows how many posts the user has

Have a variable to add to this list? Create a reply and I'll add it!


CODE SNIPPETS

Ok, now I'll show you some code snippets that are particularly useful for custom templates. Most of these code snippets use the variables above.

1. Show if logged in user has new mail or not
Code:
Mailbox: <if condition="$bbuserinfo['pmunread']">
<b><a href="$vboptions[bburl]/private.php?"><font face="Verdana" size="1" color="#78818D"> <img src="blink_arrow.gif" width="3" height="6" border="0">$bbuserinfo[pmunread] new message(s)</b>.</font></a><else />No new messages.</if>
The parts to focus on here are:
a. <if condition="$bbuserinfo['pmunread']">
b. $bbuserinfo[pmunread] new message(s)
c. <else />No new messages.</if>

What this code snippet does is check if the user has new PM messages. If the user does, it outputs a message say he has x new message(s) and puts an animated graphic to attract attention. If the user doesn't have any messages, it simply outputs "No new messages".

2. Conditional output based on user fields
For this code snippet, you will need to have set up some user profile fields that you can use. To edit or create new ones, in your ADMINCP go to "User Profile Fields" and click "User Profile Field Manager".

Code:
<if condition="$bbuserinfo['field7']=='Paid Member' OR $bbuserinfo['field7']=='Trial Member'>Output paid member only stuff here</if>
What you would use this for is if you create a new profile field and call it "member status". When the user registers you can set this to automatically give them "Free Member" status, and this input fills in with the text "Free Member". Then, if they pay you, you can login and edit their profile so that this input says the text "Paid Member" or "Trial Member", in which case this code will output special stuff for them. You could also use usergroup's instead of profile fields for this. If you want to do that then use:

Code:
<if condition="is_member_of($bbuserinfo, 6)">
Ooo, you're an admin. You get this special content here.
</if>
And if you want multiple groups to be able to access the content:
Code:
<if condition="is_member_of($bbuserinfo, 4) // Mods 
        OR is_member_of($bbuserinfo, 5) // Supermods 
        OR is_member_of($bbuserinfo, 6)"> // Admin

Insert the special content here.
</if>

3. Annoy users who haven't posted
Well, as most people know, users sometimes signup just to read posts and never post any new ones or contribute to your community. To bug them to post you can use this code snippet:

Code:
<if condition="$bbuserinfo['posts']==0">
You haven't posted any new posts yet! Get posting and help to build this amazing community! :-)
</if>

4. Custom login box
Want to put a login box to your forum somewhere on a template? Try this:

Code:
<!-- login form -->
		<form action="$vboptions[bburl]/login.php" method="post" onsubmit="md5hash(vb_login_password,vb_login_md5password)">
		<script type="text/javascript" src="$vboptions[abspath]/clientscript/vbulletin_md5.js"></script>
		<table cellpadding="0" cellspacing="$stylevar[formspacer]" border="0">
		<tr>
			<td class="smallfont" width="60"><font size="1" face="Tahoma" color="#FFFFFF">&nbsp;User Name:</font></td>
			<td><input type="text" class="button" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="1" value="$vbphrase[username]" onfocus="if (this.value == '$vbphrase[username]') this.value = '';" /></td>
			<td class="smallfont" width="100"><font size="1" face="Tahoma" color="#FFFFFF">Password:
              (</font><a href="login.php?do=lostpw"><font size="1" face="Tahoma" color="#FFFFFF">forgot?</font></a><font size="1" face="Tahoma" color="#FFFFFF">)</font></td>
			<td><input type="password" class="button" name="vb_login_password" size="10" accesskey="p" tabindex="2" /></td>
			<td><input type="submit" class="button" value="$vbphrase[log_in]" tabindex="4" title="$vbphrase[enter_username_to_login_or_register]" accesskey="s" /></td>
		</tr>
		</table>
		<input type="hidden" name="s" value="$session[sessionhash]" />
		<input type="hidden" name="do" value="login" />
		<input type="hidden" name="forceredirect" value="1" />			
		<input type="hidden" name="vb_login_md5password" />
		</form>
		<!-- / login form -->

So there you have it, some tips to get you started. Goodluck and happy template customizing!


----
Chad Fullerton
www.chadfullerton.com
Reply With Quote
  #32  
Old 08-28-2006, 11:56 AM
Majed37 Majed37 is offline
 
Join Date: Oct 2005
Posts: 6
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by toolblast
Variables you want to be able to use in any template need to be defined globally on vbulletin...

Some urls that may help:
link 1, link 2, link 3
thank you. I will read these pages .
Reply With Quote
  #33  
Old 08-30-2006, 12:01 PM
The-Ensemble's Avatar
The-Ensemble The-Ensemble is offline
 
Join Date: Jul 2006
Location: United Kingdom
Posts: 278
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks!
I thought nothing in here would be useful to me but those IF conditions really helped me out.
Cheers! ^_^
Reply With Quote
  #34  
Old 08-03-2007, 01:13 PM
toolblast's Avatar
toolblast toolblast is offline
 
Join Date: Mar 2004
Posts: 266
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Glad this thread has been helpful to people
Reply With Quote
  #35  
Old 08-18-2007, 02:43 PM
punchbowl punchbowl is offline
 
Join Date: Nov 2006
Posts: 505
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

best thread ever!
Reply With Quote
  #36  
Old 12-24-2007, 02:41 AM
wisebread's Avatar
wisebread wisebread is offline
 
Join Date: Dec 2007
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi all,

What are the variables available in the $foruminfo[] array? I'm looking to linkify the forum description box, so the name of the forum links to the forum.

TIA!
Reply With Quote
  #37  
Old 12-26-2007, 03:21 PM
hrk hrk is offline
 
Join Date: May 2007
Posts: 125
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thanks for sharing.
really help me a total newbie get started.
this should incl in the manuals.

i have one doubts .
normally we add standard css inline.

how do i direct the template to external css? and which file in edit in this?
can the standard import command be used ?

thanks
Reply With Quote
  #38  
Old 12-27-2007, 11:17 PM
toolblast's Avatar
toolblast toolblast is offline
 
Join Date: Mar 2004
Posts: 266
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi everyone!

Thanks for reading this thread and I hope you found it helpful. I'm currently putting together an ebook to help people get started with customizing vbulletin with their own pages and products/plugins. Step by step instructions (with screenshots) on how to create your very first custom product (introduction to custom php files, plugins, hooks, style templates, integrating user information, etc), as well as tips, tricks, and code snippets that you can use to get some commonly asked things done... and all in simple to understand english

If interested, shoot me a private message.

Customizing vBulletin can be fun! Let us show you how

Update:In the meantime, be sure to check out vb.org's articles section, and the vBulletin Manual.
Reply With Quote
  #39  
Old 01-28-2008, 03:05 PM
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You have $vbulletin->userinfo['username']. Where is $bbuserinfo['field6'] via the function call?
Reply With Quote
  #40  
Old 01-30-2008, 06:39 PM
Supramania's Avatar
Supramania Supramania is offline
 
Join Date: Mar 2006
Location: Woodstock, GA
Posts: 74
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is good stuff. I do have a question that isn't covered.

Say I have a multiple choice custom user profile field that is stored bitwise in the database.

Example:

Choice 1 = 1
Choice 2 = 2
Choice 3 = 4
Choice 4 = 8
Choice 5 = 16

So if a user selected choices 4 and 5, the stored value would be 24.

How could I evaluate this easily with an If/Then statement so that I could display the appropriate icons under the username in the postbit based upon each choice.

For example, the for the user above it would need to display two icons that correspond to choices 4 and 5.

If an user had selected ALL fields, the value would be 31, and it would need to display 5 icons.

I've done plenty of the <if condition="is_member_of($post, X)"> logic when it comes to usergroup membership, but this bitwise storage is confusing.

Can anyone show me a quick sample that would help clear this up for me?

Edit: I figured it out. Here's the answer for anyone looking for it:

Code:
<if condition="$post[field11] & 2">
<div><img src="images/badge2.gif"></div>
</if>
<if condition="$post[field11] & 4">
<div><img src="images/badge3.gif"></div>
</if>
Reply With Quote
  #41  
Old 03-02-2008, 11:45 PM
zmmmzz zmmmzz is offline
 
Join Date: Nov 2007
Posts: 81
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

this thread helps so much
what about that ebook?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:27 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07398 seconds
  • Memory Usage 2,325KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (7)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (1)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete