PDA

View Full Version : [PHP] Easy question about templates


MusicMan
11-19-2005, 08:44 PM
Hello, I'm trying to learn coding, I don't know a whole lot. I am developing a vbulletin 3.5.1 board and I have a question to ask about something that is pretty simple, but keeping me from progressing with development.

I found that you can make a template in the AdminCP Style Manager. I also found another thread here with code to copy to get the page to call up the template or whatever. As of right now, I have a way to make a "rules page" that will match the style of my board, but it seems that the text displayed on the page is part of the coding in the template, not in the rules.php file. Let me explain...

Here is the template I have in my AdminCP. It is named "rules".
$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
<title>$vboptions[bbtitle]</title>
$headinclude
</head>
<body>
$header

$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%" align="center">
<tr>
<td class="tcat">Rules</td>
</tr>
<tr>
<td class="alt1">Text</td>
</tr>
</table>

$footer
</body>
</html>

Then I inserted the following code to make a test page (named rules.php)

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'rules'); // change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(

);

// get special data templates from the datastore
$specialtemplates = array(

);

// pre-cache templates used by all actions
$globaltemplates = array(
'rules',
);

// pre-cache templates used by specific actions
$actiontemplates = array(

);

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################

$navbits = array();
$navbits[$parent] = 'Test Page';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('rules') . '");');

?>

What is happening is the rules.php file displays the correct style and layout of my site, the navbits show rules-related text, but the table just shows "text". So I assume I can go into the "rules template" and insert whatever text I want and it will display correctly...BUT...My goal is to have a template that I can change the text and navbits without changing the actual template. I plan on creating a lot of pages, so creating thousands of unique templates is not an option. So if someone could help me out with this issue which is probably very simple, I'd appreciate it a lot. Oh and try to "dumb it down" for someone who is brand new to coding. ;)

Guest190829
11-19-2005, 11:28 PM
You can make a new table for rules or whatever you want to put into it, and then just extract it in the .php file, finally you can display in a template.

MusicMan
11-20-2005, 01:26 AM
You can make a new table for rules or whatever you want to put into it, and then just extract it in the .php file, finally you can display in a template.

?? I don't know if that answers my question.

The code I posted does allow me to create a unique "rules" template, and if I was to insert all of the rules of my site into the text field it will make a rules page that has the same style as the rest of the site. However...that's not what I'm asking, I'm able to get that part working.

What I'm needing is a way to create a generic template that contains the style and layout of my site, a template that can be called upon by thousands of unique pages. As of right now the only way I can see to create each unique page is to create a corresponding template, since the text for the .php page has to be inserted in the "text" field within the template. So what I need is a way to manipulate the content of a page within the php code of that page, not within the template it calls for. There's no way I would ever have time to mess with coding 10,000 pages and then also programming 10,000 different templates for those pages.

There are a couple of examples of something similar to what I'm looking for on other sites, but the webmasters are impossible to get in touch with, and probably wouldn't want to help me anyway. I guess if anyone is serious about wanting to help you could PM me and I could give you a couple of links for reference.

I hope that explains it a little better, thanks for the reply. :)

MusicMan
11-25-2005, 02:20 PM
It's been 5 days...can anyone offer any help?

tnguy3n
11-25-2005, 04:34 PM
okie, in your rules.php file,

BELOW,
eval('$navbar = "' . fetch_template('navbar') . '";');

ADD:
eval('$ruletext = "' . fetch_template('ruletexts') . '";');


Then in your rules template,

REPLACE:
Text

WITH:
$ruletext


And then, create a new template named ruletexts where you can write your forum rule.

hope that helps.