Forum Moderators: coopster

Message Too Old, No Replies

need HELP w/ implementing very simple template system, please!

         

ginnymin

5:24 pm on Jun 15, 2003 (gmt 0)

10+ Year Member



hey all, i'm trying to implement a template system into my website (which i'm currently redesigning and redoing, hence all these wonderful new changes), and i'm attempting to use bTemplate. keep in mind, i'm not a born programmer... i can usually figure code out for myself and get by learning and picking up stuff on my own, but here and there i'll run into really simple problems that i probably wouldn't run into if i knew what i was doing. especially since i'm just starting with PHP.

in any case, if you go to this link, <snip> , you'll see what i'm trying to set up. hopefully on your browser it'll show up fine (there's a lot of heavy graphics and CSS positioning and i haven't tested the design on multiple browsers), so if it doesn't and looks like a big mess, i apologize. you'll see the template, which includes mostly graphics on the uppder half and the "dynamic" content part on the lower half (which is just repeating text right now), separated by the thin horizontal menu. so it all shows up, which is a good thing... it's loading the template and content.

i've tried to set it up so that when you acess "test.php" or "test.php?section=home", you'll get the "main test content" repeating text, which is via the file test.txt; when you access "test.php?section=content1" you get "content 1" repeating via content1.txt; and for "test.php?section=content2" you get "content 2" repeating via content2.txt. if you look in the upper right corner, you'll see a small menu. i've set the "CONTACT" link to for content1, the "GUESTBOOK" link for content2, and "PLACES" for home.

my problem is that most of the time, the wrong content loads. in fact, it's loading content 1 almost all of the time. when i tried the page out for the very first time, it seemed fine because it loaded the "main test content". when i tried content 1, it loaded content 1. but when i tried content 2, it stayed on content 1, and it seems to be staying put. i'm guessing once $section is set as content1 the browser or program seems to remember that and keeps that value despite all the refreshing and switching links, but i really don't know. i have no idea how to fix this? and are people seeing the same problem?

here's what i have in the test.php :

<?php
include_once('bTemplate.php');
$tpl = new bTemplate();

if ($section == 'content1') {
$title = 'content 1';
$tpl->set('title', $title);
$tpl->set('content', $tpl->fetch('content1.txt'));
}

else if ($section == 'content2') {
$title = 'content 2';
$tpl->set('title', $title);
$tpl->set('content', $tpl->fetch('content2.txt'));
}

else if ($section == 'home') {
$title = 'main content';
$tpl->set('title', $title);
$tpl->set('content', $tpl->fetch('test.txt'));
}

else {
$title = 'main content';
$tpl->set('title', $title);
$tpl->set('content', $tpl->fetch('test.txt'));
}

echo $tpl->fetch('test.tmp');
?>

all help is MUCHO APPRECIATED! i'm guessing it's something really simple for anyone who is familiar with PHP or knows what they're doing with web programming... but as for me, i'm just clueless.

hope all is doing well...

[edited by: jatar_k at 5:30 pm (utc) on June 15, 2003]

[edited by: ginnymin at 5:52 pm (utc) on June 15, 2003]

Nick_W

5:34 pm on Jun 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld!

You just got hit by a real GOTCHA! ;)

if ($section = 'content1') {

Should be

if ($section == 'content1') {

== means 'equal to' or 'is same as'

and

= means 'equals'

With me? Each time you run that script it's saying 'content IS "content1"'......

Take a look at this:
[php.net...]

Nick

[edited by: Nick_W at 5:36 pm (utc) on June 15, 2003]

jatar_k

5:34 pm on Jun 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld ginnymin,

The first thing that comes to mind is change all of your = to == in your if statements.

= is the assignment operator, which means you are assigning a new value to $section and since $section = 'content1' is the first one it is the one loading.

== is the comparison operator which is what you want to do.

<added>Nick beat me, darn ;)

ginnymin

5:47 pm on Jun 15, 2003 (gmt 0)

10+ Year Member



actually, i did have the double == at first, but then it didn't work.... so i had a crazy idea that maybe = would work and tried it, and got better resutls? i'll change it back and see hwat happens....

ginnymin

5:51 pm on Jun 15, 2003 (gmt 0)

10+ Year Member



ok, it still doesn't work! now it just stays on "main test content" and doesn't change to content 1 or content 1... any ideas?

Nick_W

5:54 pm on Jun 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How are you passing the script the $content var?

Nick

jatar_k

5:59 pm on Jun 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Since you are passing the var via GET try

if ($_GET['section'] == 'content1') {

or at the top you could do

$section = $_GET['section'];

Nick_W

6:02 pm on Jun 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, I'm a skimmer, I missed that but suspected it, jatar is of course, spot on I reckon...

Nick

ginnymin

6:06 pm on Jun 15, 2003 (gmt 0)

10+ Year Member



the

if ($_GET['section'] == 'content1') {

is working great!

thanks so much for yalls help, i figured i just didn't know some things :)

jatar_k

6:10 pm on Jun 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Take a read through this
PHP Predefined Variables [php.net]

I missed it the first time too Nick, your question tipped me off ;)