vBulletin Mods

The Official vBulletin Modifications Site
https://www.vbulletin.org/forum/showthread.php?t=113489

Template Editing - All the variables and coding bits you need to know!
by toolblast
19 Apr 2006 21:59

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

Brad 20 Apr 2006 20:03

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.


Zero767 21 Apr 2006 16:47

Thanks, that login code really helped me, great post!

toolblast 21 Apr 2006 23:22

Quote:

Originally Posted by Zero767
Thanks, that login code really helped me, great post!

No problem Zero767 :) Glad it helped!

bairy 26 Apr 2006 18:53

Quote:

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.

toolblast 26 Apr 2006 19:11

Thanks Bairy!

Yes, it is probably best to use the code you provided for the usergroup detection, it is faster and more effective.

FLMom 26 Apr 2006 19:13

Wow! This really explained a lot to me! Thanks for posting this!

Pro 27 Apr 2006 04:20

Excellent tutorial! I needed to figure out a few things and this answered almost every one of my questions!!! :D

chipet 28 Apr 2006 18:41

How do I do it if I want to have the login on a different homepage?

toolblast 28 Apr 2006 19:09

Thanks FLMom and Pro for the kind words. I am glad this has helped you.

Quote:

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:

Quote:

<form action="http://www.mysite.com/forum/login.php"...

Boofo 28 Apr 2006 20:54

Quote:

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. ;)

chipet 28 Apr 2006 21:40

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.

Brad 28 Apr 2006 22:47

Quote:

Originally Posted by Boofo
It doesn't seem to like that in if condition = statements, though. ;)

In these places simpy drop the brackets :)

Boofo 28 Apr 2006 23:12

Quote:

Originally Posted by Brad
In these places simpy drop the brackets :)

In a condition, would that be the same as <if condition="$show['member']">?

Adrian Schneider 02 May 2006 05:21

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.

toolblast 02 May 2006 17:27

Interesting. Thanks for sharing that SirAdrian, it is always best as a programmer to keep things as clear to look at and logical, I like the if statement format you showed.

dwbro1 06 May 2006 23:14

Thanks this is great!

evofile 08 May 2006 21:50

hooooooo tnx bro nice writing

SaN-DeeP 09 May 2006 01:57

thanks for sharing

bashy 11 May 2006 20:42

Thanks for a great post and thanks to the other members/staff that have contributed, this will come in really handy for e when i create new page that im working on, Just out of interest, i take it these variables will work within something like Logicans Web Templates? I am sure it will but i just want to make sure? :)

genchacker 26 May 2006 18:59

ı did new user fields
how can ı showing new page first members new fields

5IVEO 25 Aug 2006 05:43

So how is it, and where is it you add background images instead of just colors?

So far this has helped me alot.

toolblast 25 Aug 2006 19:52

Thanks to everyone for your support with this thread. I appreciate your kind words.

@Bashy: I'm not sure what Logicians's templates are.. I haven't used them myself. But I assume it would work if the templates integrate with the vbulletin scripting structure

@Genchacker: I'm not sure what exactly you're trying to do. Please elaborate in more detail.

@5IVEO:

To add background images in templates you just use the standard HTML code for tables and bgimage, etc. or css background image.

If you're wanting to put images in your templates, you can go into admincp and for 'background' for any of those style bits you can use something like "url(images/gradients/gradient_tcat.gif) repeat-x top left".

Adrian Schneider 25 Aug 2006 19:56

Quote:

4. $headerinclude - Very useful, this variable will output the username/nickname of the user currently logged in.
Two errors here... one is obvious (copy pasted from line above it), second is that it's $headinclude (not head"er").

toolblast 25 Aug 2006 20:51

Sorry. It is now 'headinclude' instead of 'header'

Adrian Schneider 25 Aug 2006 20:57

$headinclude contains the 'headinclude' template, not the current username...

toolblast 25 Aug 2006 21:17

Ya, there were duplicate descriptions for some reason. Fixed it now :) Thanks!!

Majed37 26 Aug 2006 16:27

what if wana use a custom variable in php file to include in a template ?

for example :
if I write in postings.php :
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

can I use this variable directly in any template ?

toolblast 26 Aug 2006 17:25

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

5IVEO 27 Aug 2006 01:59

Quote:

Originally Posted by toolblast
Thanks to everyone for your support with this thread. I appreciate your kind words.

@Bashy: I'm not sure what Logicians's templates are.. I haven't used them myself. But I assume it would work if the templates integrate with the vbulletin scripting structure

@Genchacker: I'm not sure what exactly you're trying to do. Please elaborate in more detail.

@5IVEO:

To add background images in templates you just use the standard HTML code for tables and bgimage, etc. or css background image.

If you're wanting to put images in your templates, you can go into admincp and for 'background' for any of those style bits you can use something like "url(images/gradients/gradient_tcat.gif) repeat-x top left".

Thanks for the help I greatly appreciate it! Now I can work on making my own theme.

Majed37 28 Aug 2006 13:56

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 :) .

The-Ensemble 30 Aug 2006 14:01

Thanks!
I thought nothing in here would be useful to me but those IF conditions really helped me out.
Cheers! ^_^

toolblast 03 Aug 2007 15:13

Glad this thread has been helpful to people :D

punchbowl 18 Aug 2007 16:43

best thread ever!

$foruminfo[] array
by wisebread
24 Dec 2007 04:41

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!

hrk 26 Dec 2007 17:21

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

ebook
by toolblast
28 Dec 2007 01:17

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.

petteyg359 28 Jan 2008 17:05

You have $vbulletin->userinfo['username']. Where is $bbuserinfo['field6'] via the function call?

Supramania 30 Jan 2008 20:39

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:


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


zmmmzz 03 Mar 2008 01:45

this thread helps so much
what about that ebook?

aisais 11 Jul 2008 04:49

Excellent thread. Thanks

katwomanofsteel 15 Aug 2008 17:56

Just read your variables article and it was very helpful! However, I still can't figure out how to pull into the postbit template, a poster's paid subscription information in 3.5.8.

Tried an if condition to check for $user['donator'] (hoping this would grab the check for paid subscriptions field in the user table) but that isn't working and I can't figure out where in the db the field is for the user's paid subscriptions...

Any ideas?

ForgotenDynasty 18 Aug 2008 05:22

if i want to use these on a nonvb page all i need to do is include the global.php correct?

silly rabbit 02 May 2009 13:22

Quote:

Originally Posted by aisais (Post 1572461)
Excellent thread. Thanks

ditto! And Thanks!

Another Question (this thread seems appro): those pesky 'lil "phrase variables" embedded within vB phrases (ie: the ones that look like {1} and ofttimes come with plugins) what's the easiest way to add more or change 'em?

Forgive if stupid question,

Rabbit

mokonzi 24 Feb 2010 22:44

Sorry to resurrect a seriosuly old article, but since I found this useful in 3.7 and 3.8, it might be nice to get some updated info in here...

So...

My question is what is the proper {vb:raw} expression to put a profile field into a template?

TalkVirginia 28 Feb 2010 10:19

Instead of adding 4.x info to this article.. Might want to just do a new one for 4.x and add a link to it, but I'm sure the 'powers that be' already knew that. ;)

Gator Bite 07 May 2010 17:12

OK, I've banged my head pretty good on this one. We have a vb 3.8.4 forum and we would like to change the recipient field on the activation e-mail from the 'username' to the members real first name, which we have stored in Profile Field 15. Does anyone know how we can achieve this?

Thanks in advance for your time.

Mike

MathewC 11 May 2010 14:07

Is there a way to display content to the user logged in and not to everyone logged in?

Such as,

License Code:
54575e4

Each license code is different thus every member should only see their license code?

BirdOPrey5 28 Jun 2010 22:26

Quote:

Originally Posted by ForgotenDynasty (Post 1601157)
if i want to use these on a nonvb page all i need to do is include the global.php correct?

I'm curious if there is a way to call these fields from a php file as well.

gamerzhut 21 Jul 2010 17:58

Really useful thanks :)

ubcforums 30 Jul 2010 17:28

Please tell me how to check if member subscribed to thread or not ?

Thanks :)

michaelclyde 01 Jan 2021 19:58

Cool thread, know it's old (seen it before) but if locked out of AdminCP (suspect hacked) and wanted to access/check/edit templates directly from the CPanel mysql database . .

On version 3.8.2 in which fields would these templates be found?

ONE PROBLEM: Upon "view source" in header I get right-justified (see below) instead of dir="ltr" (how to correct this)?

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



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

Powered by vBulletin® Version 3.8.14
Copyright © 2021, MH Sub I, LLC dba vBulletin. All Rights Reserved. vBulletin® is a registered trademark of MH Sub I, LLC
Copyright ©2001 - , vbulletin.org. All rights reserved.