Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-25-2002, 10:22 PM
Mystis's Avatar
Mystis Mystis is offline
 
Join Date: Jul 2002
Location: Minnesota
Posts: 72
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Uncharacteristically newbish question from me...

Hey there everyone,
I'm an experienced PHP programmer who is just starting to delve into vB hacking. I've been picking apart the code and understand almost everything there is, except for the template system. I understand it's function and why things happen, but not quite how they happen. For example, I've been trying fruitlessly for the last 20 minutes to write a simple header/footer page with no content, and it just doesn't make sense to me. I'm sure that I'm just reading too hard into the problem, but I'm just vexed by everything, and I was wondering if someone could give me a little Templates 101 lesson? If someone could even write up the aforementioned header/footer page I'm sure that I could figure it out.

I hate asking because it makes me sound so newbish, which I'm definately not (I'm actually the programming forum moderator at Somethingleet), but this is something that's just got me in a corner. I'm normally the one answering the questions, not asking them. I guess you've got to start somewhere!

Thanks everyone for your help!
Mystis
Reply With Quote
  #2  
Old 12-26-2002, 01:26 AM
Sebastian's Avatar
Sebastian Sebastian is offline
 
Join Date: Oct 2002
Location: America
Posts: 488
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi.

are you trying to change the vbulletin footer/header?

There is already a header and footer template for vbulletin, why not edit those to your needs?

or are you trying to add a footer and header to a custom page?
Reply With Quote
  #3  
Old 12-26-2002, 01:55 AM
Auero Auero is offline
 
Join Date: Aug 2002
Posts: 50
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

..Styles
...Fonts/Colors/Etc
Header, Footer

..Templates
Header, Footer

The variable for header and footer is $header $footer

If you call the global file from a file you create and place it in the forum/ directory then it will place the header and footer into that page for you.
Reply With Quote
  #4  
Old 12-26-2002, 03:37 AM
Mystis's Avatar
Mystis Mystis is offline
 
Join Date: Jul 2002
Location: Minnesota
Posts: 72
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So this should automatically place the head and foot in the page? Because it most definately doesn't.
PHP Code:
<?php
error_reporting
(7);
require(
'global.php');
?>
Neither does (although it does echo just the header)
PHP Code:
<?php
error_reporting
(7);
require(
'global.php');
eval(
"dooutput(\"".gettemplate('header')."\");");
eval(
"dooutput(\"".gettemplate('footer')."\");");
?>
or

PHP Code:
<?php
error_reporting
(7);
require(
'global.php');
echo 
$header;
echo 
$footer;
?>
Reply With Quote
  #5  
Old 12-26-2002, 05:13 AM
mr e's Avatar
mr e mr e is offline
 
Join Date: Dec 2001
Posts: 461
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

well this is just saying display the content in the template "footer", there's another one in vb (an eval) that is like gettemplate or something like that

eval("dooutput(\"".gettemplate('footer')."\");");

and this says, make the variable work in the current template

eval("\$statstable .= \"".gettemplate('battle_statsbottom')."\";");
Reply With Quote
  #6  
Old 12-26-2002, 05:36 AM
Mystis's Avatar
Mystis Mystis is offline
 
Join Date: Jul 2002
Location: Minnesota
Posts: 72
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Alright, I've struggled this far:

PHP Code:
<?php
error_reporting
(7);
require(
'global.php');
eval(
"\$template_nav .= \"".gettemplate('template_nav')."\";");


eval(
"dooutput(\"".gettemplate('template')."\");"); 

?>
and then the template 'template'

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>$bbtitle - Page Title</title>
	$headinclude
</head>
<body>
$header
<br />
$template_nav
<br /><br />
$footer
</body>
</html>
And then template_nav obviously being some navigation. What I'm really struggling with now is trying to set up database extracted data in the proper area. I can query the database alright, but I can't figure out how to output the data where I want it to go. Any pointers? Thanks!
Reply With Quote
  #7  
Old 12-26-2002, 05:06 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you include global.php there is no need to call the header and footer templates...

You can just call the template you need for your page and obviously create it and then stick $header and $footer in the template when you want them

Remember when calling a template in a file if it's being called all the time then add a $templatesused variable which includes the names of the templates called in the file

- miSt
Reply With Quote
  #8  
Old 12-26-2002, 05:33 PM
tHE DSS's Avatar
tHE DSS tHE DSS is offline
 
Join Date: Jun 2002
Location: UK
Posts: 113
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The template system is a powerful dynamic/expandable type system. It's main power comes from the 'eval()'.

Say you have a little template titled "twoPlusTwo", and it contained :

Code:
<table cellpadding="0" cellspacing="0" border="0">
	<td align="left" valign="center">2 + 2 = $calc_result</td>
</table>
... to get that ready for output, you would call that template in via the 'gettemplate()' function, like this :

PHP Code:
$calc_result 2;
eval(
"\$twoPlusTwo = \"".gettemplate('twoPlusTwo')."\";"); 
... as we are 'evaluating' the function and return data here as a 'string' variable, your '$calc_result' value is 'expanded' by PHP.

The 'gettemplate()' function returns the contents of 'twoPlusTwo', into the string type variable we've named 'twoPlusTwo', at the start of the 'eval()'.

You notice the contents of the template has the bit '$calc_result'.... well, because you've put a value into that variable name, the getting the template in this way, puts your value into the template (your value gets expanded, and your dynamic string is created).

It's just like doing this :

PHP Code:
$calc_result 2;
echo 
"2 + 2 = $calc_result"
... except, the template system gives much much more scope for outputting complete pages, and for re-organising your pages.

With this system, you use the gettemplate() function to retrieve all your little bits of the webpage - they are smaller chunks for easier managment, and for giving you more scope.

Once you've retrieved all of your templates into string variables, and the data inside has been expanded, you are then ready for output.

This is where you need an over-all page layout template. Like this, called 'testPage', for example :

Code:
<html>
<head>
	<title>Test</title>
</head>
<body bgcolor="#ffffff" text="#000000">
This is our example of how the vB template system works.
<p>
$twoPlusTwo
</html>
... notice that you have the $twoPlusTwo variable (contiaining your previously generated template) named inside the main page display template, just like we did above, when using the result of the little calculation.

What you then do, once all your page templates are generated in the above way, is make a call to the 'dooutput()' function, like this :

PHP Code:
eval("dooutput(\"".gettemplate('testPage')."\");"); 
... same deal here. We get the template 'testPage', which contains our page layout and $twoPlusTwo variable, which contains the now fully expanded 'twoPlusTwo template, and we send that to the dooutput() function.

As you now have all your dynamically created templates inside the computer memory, all your variables get expanded in the dooutput() function, and then the dooutput() function simply uses the "echo" to echo the whole job lot out to the browser.

It's very powerful, very simple, very very good.

I'm not a great teacher... so hopfully i've helped. aranoid:

That's how the system works anyway, and you can use it in any way you see fit.
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 12:26 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04480 seconds
  • Memory Usage 2,251KB
  • Queries Executed 11 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete