Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
Template Editing - All the variables and coding bits you need to know!
toolblast
Join Date: Mar 2004
Posts: 266

I create innovative media and design

by toolblast toolblast is offline 19 Apr 2006

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

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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".


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

And if you want multiple groups to be able to access the content:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


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:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


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


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


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


----
Chad Fullerton
www.chadfullerton.com

Last edited by toolblast; 25 Aug 2006 at 20:17..
Views: 32933
Reply With Quote
Comments
  #2  
Old 20 Apr 2006, 19:03
Brad Brad is offline
 
Join Date: Nov 2001
You can access information in objects directly with the templates. For example this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Can be written as:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #3  
Old 21 Apr 2006, 15:47
Zero767 Zero767 is offline
 
Join Date: Apr 2006
Thanks, that login code really helped me, great post!
Reply With Quote
  #4  
Old 21 Apr 2006, 22:22
toolblast's Avatar
toolblast toolblast is offline
 
Join Date: Mar 2004
Real name: Chad
Originally Posted by Zero767
Thanks, that login code really helped me, great post!
No problem Zero767 Glad it helped!
__________________
~~My Portfolio~~
Reply With Quote
  #5  
Old 26 Apr 2006, 17:53
bairy bairy is offline
 
Join Date: Oct 2005
Real name: Chris
Originally Posted by toolblast
And if you want multiple groups to be able to access the content:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.
is_member_of can be overloaded, a shorter version of the above could be:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

BTW, group 7 is mods, not group 4.

Last edited by bairy; 26 Apr 2006 at 17:57.
Reply With Quote
  #6  
Old 26 Apr 2006, 18:11
toolblast's Avatar
toolblast toolblast is offline
 
Join Date: Mar 2004
Real name: Chad
Thanks Bairy!

Yes, it is probably best to use the code you provided for the usergroup detection, it is faster and more effective.
__________________
~~My Portfolio~~
Reply With Quote
  #7  
Old 26 Apr 2006, 18:13
FLMom's Avatar
FLMom FLMom is offline
 
Join Date: Feb 2006
Real name: Cori
Wow! This really explained a lot to me! Thanks for posting this!
Reply With Quote
  #8  
Old 27 Apr 2006, 03:20
Pro Pro is offline
 
Join Date: Aug 2002
Excellent tutorial! I needed to figure out a few things and this answered almost every one of my questions!!!
Reply With Quote
  #9  
Old 28 Apr 2006, 17:41
chipet chipet is offline
 
Join Date: Oct 2005
How do I do it if I want to have the login on a different homepage?
Reply With Quote
  #10  
Old 28 Apr 2006, 18:09
toolblast's Avatar
toolblast toolblast is offline
 
Join Date: Mar 2004
Real name: Chad
Thanks FLMom and Pro for the kind words. I am glad this has helped you.

How do I do it if I want to have the login on a different homepage?
All you gotta do Chipet is copy the code and place it into an html or php file on your server (doesnt have to be in the forum folder), and then just make sure where it says "action="$vboptions[bburl]/login.php" erase the $vboptions[bburl]/ and replace it with the path to your forum.

So it would be something like:

<form action="http://www.mysite.com/forum/login.php"...
__________________
~~My Portfolio~~
Reply With Quote
  #11  
Old 28 Apr 2006, 19:54
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Real name: Rob
Originally Posted by Brad
You can access information in objects directly with the templates. For example this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Can be written as:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.
It doesn't seem to like that in if condition = statements, though.
Reply With Quote
  #12  
Old 28 Apr 2006, 20:40
chipet chipet is offline
 
Join Date: Oct 2005
Hm. when I laying the code on a different homepage it doen't login when I try login, Im just being redirected to the forum without being loged in.
Reply With Quote
  #13  
Old 28 Apr 2006, 21:47
Brad Brad is offline
 
Join Date: Nov 2001
Originally Posted by Boofo
It doesn't seem to like that in if condition = statements, though.
In these places simpy drop the brackets
Reply With Quote
  #14  
Old 28 Apr 2006, 22:12
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Real name: Rob
Originally Posted by Brad
In these places simpy drop the brackets
In a condition, would that be the same as <if condition="$show['member']">?
Reply With Quote
  #15  
Old 02 May 2006, 04:21
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Conditions are executed like so:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Because they aren't parsed through double quotes like the rest, there is no need for the braces. I always use the full object vars in conditions, though the shorthand versions appear to work fine as well.

@Boofo: looking at global.php lines 431 (for me anyway):

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

so to answer your question: yes. It's probably "best" to use $show variables in templates as much as possible, because it keeps the application logic seperate from your templates, but for things as simple as that it shouldn't really matter.
__________________
Sr Software Developer / Tech Lead
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

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


New To Site? Need Help?

All times are GMT. The time now is 00:55.

Layout Options | Width: Wide Color: