First Look at vBulletin 4 Template Variables
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: Code:
{vb:type value.key} Examples: Code:
$bbuserinfo[userid] => {vb:var bbuserinfo.userid} Code:
{vb:var variable} If your variable outputs HTML code, then you'll want to use raw instead. RAW Code:
{vb:raw variable} PHRASE Code:
{vb:phrase phrase, param1, param2...} If the phrase includes HTML code, you should use rawphrase instead. RAWPHRASE Code:
{vb:rawphrase phrase, param1, param2...} STYLEVAR Code:
{vb:stylevar variable} 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. HTML Code:
<vb:if condition="$show['bbcodephp']"> |
Cool, though I don't get it why we can't use normal PHP anymore, way more clarified!
|
can anyone help me with this i am unsure what to chnage it to
value="$bbuserinfo[email]" |
Quote:
I think you are wanting to do this: Code:
value="{vb:raw bbuserinfo.email}" |
Quote:
do you know anything of this $vbgpc[additional_usernames] |
Quote:
|
can anyone help me convert his old template variable to vb4 please
$vbphrase[threads]: $totalthreads $vbphrase[posts]: $totalposts $vbphrase[members]: $numbermembers |
Quote:
{vb:phrase threads}: {vb:var totalthreads} {vb:phrase posts}: {vb:var totalposts} {vb:phrase members}: {vb:var numbermembers} |
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? |
can someone help me with this code
i've gone wrong somewhere in the code and can't figure it out Code:
|
can anyone help solve this problem
i want to include the following within a template PHP Code:
|
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 PHP Code:
And the template that should display the whole looped conteend PHP Code:
$data is an array like PHP Code:
My "NAMES" template looks like this ... Code:
<div>{vb:raw names_loop}</div> My "names_loop" template looks like this ... Code:
<div style="magin: 10px; padding: 10px;"> Can anyone help, please? :confused: Thanks. |
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? |
Quote:
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 HTML Code:
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: PHP Code:
|
Thanks, it's working now
|
Does anyone know how to get forumIDs and bbuserinfo from this new system?
I'm trying to use it as follows, but it doesn't work... Code:
header.php?fid={vb:var forum.forumid}&pid={vb:var bbuserinfo.field9} I'm trying to use this in the HEADER template. It seems that you can no longer call forum and user information in the header template. So it seems forcing specific headers to specific forums is IMPOSSIBLE in VB4. |
i have a template i wish to add to the navbar template
i called it template2 i want to place my custom template above Code:
<div id="breadcrumb" class="breadcrumb"> Code:
{vb:raw navbar2} Code:
|
How would we use $vbulletin->options in this?
I am trying to use {vb:options media_thumb_dir} but its not working... |
So basically the variables were changed for no reason just so that non-coders could understand it? Those new variables look a lot more confusing to me.
|
Not sure why it was changed, but Jaxel:
{vb:raw vboptions.media_thumb_dir} |
Can someone please convert these for me?
Code:
$spacer_open |
Quote:
{vb:raw spacer_open} {vb:raw spacer_close} unless 4.x has a different mechanism. Double check the brackets, I'm not sure if they are correct. |
Nope.. they aren't correct. I already tried that before posting here :)
|
Quote:
HTML Code:
{vb:raw spacer_open} PHP Code:
|
Quote:
|
Hi everyone
i have a php file that contain some variable and i tried to connect them together like a URL (link) $folder = $folders = $vbulletin->options['folder']; $subfolder = $folders = $vbulletin->options['subfolder']; $file = $folders = $vbulletin->options['file']; $url = $folder/$subfolder/$file; then i got an error like Warning: Division by zero in E:\xampp\htdocs\test\test.php on line 184 note: those code on line 184 any help or suggestion will be appreciated or with those variable how can i put them in my template {vb:var folder}/{vb:var subfolder}/{vb:var file} within $templater->register(''); is it correct ? thanks, |
Quote:
|
thank you very much TalkVirginia
it works |
Quote:
|
The template hook, $template_hook['showthread_above_posts'] for example, is the variable you want to populate to display your data. The hook location, showthread_complete for example, is the hook in the php file that you use to load the template variable with your data by rendering a template for instance. You can select these hook locations in the plugin manager drop down when you create a new plugin.
|
Quote:
$MyVar = $templater->render(); ... I registered my PHP code at postbit_display_start. Then inside of "postbit_legacy" -- replace {vb:raw post.message} with {vb:raw MyVar}. There appears to be a variable scope problem, or I'm not accessing $MyVar correctly inside of postbit_legacy. When I render into one of the hooks, the rendered display does show up correctly -- so I know the mechanics of what I'm doing are all correct. |
Quote:
|
Does anyone know the usergroup HTML markup variable names?
To be clear, I'm not looking to use {vb:raw post.musername}, I want to get the HTML markup without the username. |
All times are GMT. The time now is 08:42 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|