Forum Moderators: coopster

Message Too Old, No Replies

using more then one page in a template file?

using bTemplate

         

nfs2

2:26 am on May 18, 2006 (gmt 0)

10+ Year Member



Here's my problem. I need to have a few different pages in one template file. I run a blogging site, and each user has their one single template file that thye can edit as they wish. It includes the css as well as the html.

The problem is that each blog has a few pages. For example, there's a picture page, and a user info (bio) page. Currently these are using different template files.

Is there a way to get them all on the same template file? Like how in phpbb they use a <!--SWITCH --> to display different pages on the same template

Does anyone know what i mean?

eponymous

10:13 am on May 18, 2006 (gmt 0)

10+ Year Member



It seems to me that query strings could do what you're after. So the urls would be something like:

[domain.com...] (bio page)
[domain.com...] (picture page)

In the top of mytemplate.php, you'd write some php to collect the value of 'display' and then display the relevent data.

Co-incidentally, I just came across this thread on query strings in the forum, which might be a good place to start if you're unfamiliar with how they work.

[webmasterworld.com...]

Hope that helps. :)

dreamcatcher

1:17 pm on May 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



includes maybe?

dc

jatar_k

4:50 pm on May 18, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could use a switch in your template file

you could do it by pagename

get the pagename out of the requested url
store that in a variable
use that for the switch control

nfs2

6:50 pm on May 18, 2006 (gmt 0)

10+ Year Member



Yeah im thinking a switch would be best. All the pages are generated by the same php file, and are displayed with a get request

ie; journal.php?view=pictures or journal.php?view=profile

Im just not sure how to implement the switch. bTemplate is small on documentation or support. Its kinda old

jatar_k

7:46 pm on May 18, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$whichpage = $_GET['view']; 
switch ($whichpage) {
case 'pictures':
// code here
break;
case 'profile':
// code here
break;
default:
echo 'you entered an invalid pagename';
break;
}

something like that, you need the default case to handle if someone enters junk in your url. You may need to send 404 headers for that as it wouldn't be a valid page. Or even just send them your standard 404 page.

You would just need to weave your template code into those cases. If you figure out just what your templates are doing it shouldn't be too bad.

nfs2

8:18 am on May 19, 2006 (gmt 0)

10+ Year Member



Thanks for trying, but im not sure im getting it. Then again, im probably not explaining my problem very well..

I can switch modes in the journal.php file, between $_GET['view'] == pictures and $_GET['view'] == profile, the problem is i can only use html in the journal.php file to display those, because the template file has all the journal code in it..

How can i explain this.. I have one template file. Lets call it myname.tpl. In that is all the html and variables that display the journal. Now, i can change the variables sent to the template depending on the section being viewed (like in that suggestion you made) but that doesnt get rid of the HTML for the journal section, so just doing that wont work..

Do you know what i mean? This is hard to explain to i hope im making sence

EDIT:

Just to make clear, there are 2 files involved. The journal.php file and the template.tpl file.

Right now when vieing pictures, its done directly from journal.php without any template file

if ($_GET['view'] == "pictures") {

//i simply put the html and php variables here to display pictures, same if it was for the profile

}

But if none of those are called, then the main journal page is displayed with the template

else {
include_once('bTemplate');
$tpl->set('variable_1', $variable_1);
$tpl->set('variable_2', $variable_2);
//and so on

//call the template
echo $tpl->fetch("template.tpl");