![]() |
|
Article Options |
First Look at vBulletin 4 Template Variables
by
![]() Reposted from my site at www.vbcodex.com Actually, Scott's blog was the first look but I am going to talk about vBulletin 4's Template Variables today. Back in the beginning, it was decided that vBulletin needed an easy to use template system. This also required that we allow PHP variables that could be evaluated and displayed to the end user in order to get the data out. This was simple and easy since PHP at its beginning was just a simple templating engine itself. However over time, it became apparent that we needed our own structures in order to coax HTML along and present dynamic data to the user while allowing the designer/site owner control and not requiring knowledge of PHP. With that the <if> and <phrase> tag constructs were developed in 3.0 and there was much rejoicing. Later it became apparent that programmers wanted to be able to easily inject their own code into the templates without bothering the site owner. At first they used regular expressions and other replacement techniques. However as templates were updated or changed, they could break these techniques so the concept of Template Hooks were born. Now developers could assign their code to a specific variable and have it appear without the site owner doing anything. Unfortunately, template hooks aren't used as widely as they could be so the above techniques are still used. The problem though with template hooks, <if> conditionals and <phrase> tags is that it made it very difficult to work with templates in tools like Dreamweaver and Go Live!. Syntax highlighting was off, variables didn't render and preview was a general mess. With the move to an object oriented template system in vBulletin 4, this would have become even worse over time. So the developers decided to move vBulletin's proprietary tags to their own namespace and create a better way of presenting variables within the templates. For variables, they adopted a 'curly node' syntax that moves away from the traditional PHP variable system and tells the system how to process each type of variable. vBulletin 4 will ship with support for a variety of these variables for different purposes. The variable name tells vBulletin how to process the output. Today, I want to go over some of these. Variable format:
This format tells vBulletin that it needs to process the variable through curly node syntax. The type tells vBulletin which class to use. If you look at the format above, you'll see there are no $ or [] used. This is an attempt to make the variable easier to use for non-programmers. So instead we'll use a 'dot' notation for variables. As a designer and developer, you'll use several types primarily. These are var, raw, phrase, rawphrase, stylevar and link. I'll talk about the first five today. Examples:
VAR
Allows you to output any variable. The output will be processed through htmlspecialchars_uni() to prevent any kind of potential XSS issues. If your variable outputs HTML code, then you'll want to use raw instead. RAW
This will bypass encoding the output to make it safe. This should be used to information that is considered safe and verified in PHP already. An example would be including another template within the current template like the header template. Raw should never be used with user input. PHRASE
Allows you to process and output phrases that are available to the page. The system will include as many parameters as listed in the parsing of the phrase. The phrase will be passed through htmlspecialchars_uni() to make it safe. If the phrase includes HTML code, you should use rawphrase instead. RAWPHRASE
Same as phrase above but does not encode the output to make it safe. As with raw variables, this should only be used for data that is verified as safe within the PHP code. STYLEVAR
This is a shortcode. You could use {vb:var stylvar.variable} as well. However this allows you to differentiate between stylevars and standard variables. It ultimately makes the code easier to read and should be used for any style variables that you want to use. Summary These are just some of the variables being used. There are other types that I will cover later. These include the previously mentioned link but also include date, time, number, if, escapejs, urlencode, and math. To finish today, I will leave you with a template example.
The following members like this post: mohammad6006
|
||||||||||||||||||||||||||||||||
Views: 24913
|
Comments |
#2
|
|||
|
|||
Cool, though I don't get it why we can't use normal PHP anymore, way more clarified!
No members have liked this post.
|
#3
|
|||
|
|||
can anyone help me with this i am unsure what to chnage it to
value="$bbuserinfo[email]"
__________________
http://www.multihunters.co.uk - all your coding needs No members have liked this post.
|
#4
|
||||
|
||||
Originally Posted by simonhind
Please explain a little better what you are wanting to do.![]()
I think you are wanting to do this:
No members have liked this post.
|
#5
|
||||
|
||||
Originally Posted by BBR-APBT
thx for the help![]()
do you know anything of this $vbgpc[additional_usernames]
__________________
http://www.multihunters.co.uk - all your coding needs No members have liked this post.
|
#6
|
||||
|
||||
That looks like come from a modification. Ask in that thread please.
No members have liked this post.
|
#7
|
|||
|
|||
can anyone help me convert his old template variable to vb4 please
$vbphrase[threads]: $totalthreads $vbphrase[posts]: $totalposts $vbphrase[members]: $numbermembers
__________________
http://www.multihunters.co.uk - all your coding needs No members have liked this post.
|
#8
|
|||
|
|||
Originally Posted by simonhind
![]()
{vb:phrase threads}: {vb:var totalthreads} {vb:phrase posts}: {vb:var totalposts} {vb:phrase members}: {vb:var numbermembers}
__________________
No members have liked this post.
|
#9
|
|||
|
|||
What is the variable for the number of unread private messages?
I used to use $vbphrase[unread_x_nav_compiled] What's the vb4 version? No members have liked this post.
|
#10
|
||||
|
||||
can someone help me with this code
i've gone wrong somewhere in the code and can't figure it out
__________________
http://www.multihunters.co.uk - all your coding needs No members have liked this post.
|
#11
|
||||
|
||||
can anyone help solve this problem
i want to include the following within a template
how can i do this and do i ned to include anything in the php file for it to work within a template
__________________
http://www.multihunters.co.uk - all your coding needs No members have liked this post.
|
#12
|
||||||||||||||||||||
|
||||||||||||||||||||
![]()
I can't convert my custom pages until i know how to access and loop with templates again. It is nice to know how to access one single var or single var in an array but how to loop? I did try my luck with ... (but without any success, yet ...)
Template i need to loop for output
And the template that should display the whole looped conteend
$data is an array like
My "NAMES" template looks like this ...
My "names_loop" template looks like this ...
So far i can access all the vars in my array with {vb:var names.0.name} or {vb:var names.0.age} but i can't use it in templates to loop an output. Can anyone help, please? ![]() Thanks.
__________________
ohhm ![]() No members have liked this post.
|
#13
|
|||
|
|||
I'm trying to use a variable in SHOWTHREAD, but it's not showing for some reason.
Hook Location: showthread_start variable: $msgbox template variable: {vb:raw msgbox} What can be wrong? No members have liked this post.
|
#14
|
||||||||
|
||||||||
Originally Posted by Ducks
Depending on where you want to place it. For example, if you want to place above the thread, use the showthread_above_posts template hook, then create a plugin using the showthread complete hook location. If you open showthread.php, examine around line 2176 and below. ![]()
Try this example: 1. Add a new custom template with the following contents: Product: vBulletin (or if you are creating a mod, choose your product id) Style: Style of your choice Title: mytemplate
2. Create a new plugin: Product: vBulletin (or if you are creating a mod, choose your product id) Hook Location: showthread_complete Execution Order: Leave as default Plugin PHP Code:
Plugin Is Active: Yes
__________________
Jim - Webadmin 3:33am Paranormal Research - History will always repeat itself but sometimes the past never leave vb4.x Email Reminders for Inactive Users, Add Mass Child Forums for vb3.8.6 & vb4.1.2 No members have liked this post.
Last edited by TalkVirginia; 19 Mar 2010 at 09:18. |
#15
|
|||
|
|||
Thanks, it's working now
No members have liked this post.
|
![]() |
«
Previous Article
|
Next Article
»
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Article Options | |
|
|
New To Site? | Need Help? |
All times are GMT. The time now is 00:12.