PDA

View Full Version : Uncharacteristically newbish question from me...


Mystis
12-25-2002, 10:22 PM
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

Sebastian
12-26-2002, 01:26 AM
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?

Auero
12-26-2002, 01:55 AM
..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.

Mystis
12-26-2002, 03:37 AM
So this should automatically place the head and foot in the page? Because it most definately doesn't.
<?php
error_reporting(7);
require('global.php');
?>

Neither does (although it does echo just the header)
<?php
error_reporting(7);
require('global.php');
eval("dooutput(\"".gettemplate('header')."\");");
eval("dooutput(\"".gettemplate('footer')."\");");
?>

or

<?php
error_reporting(7);
require('global.php');
echo $header;
echo $footer;
?>

mr e
12-26-2002, 05:13 AM
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')."\";");

Mystis
12-26-2002, 05:36 AM
Alright, I've struggled this far:

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


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

?>

and then the template 'template'

<!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!

Dean C
12-26-2002, 05:06 PM
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 :p

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 :p

- miSt

tHE DSS
12-26-2002, 05:33 PM
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 :


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


$calc_result = 2 + 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 :


$calc_result = 2 + 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 :


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


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. :rolleyes: :paranoid: ;)

That's how the system works anyway, and you can use it in any way you see fit.