HTML Help

Go Back   HTML Help Central > Site Building Central > Server-Side Stuff

Register Now for FREE!
Join HTML Help Central. To sign up for your FREE account INSTANTLY fill out the form below!

Username: Password: Confirm Password: E-Mail: Confirm E-Mail:
 
Image Verification
Please enter the six letters or digits that appear in the image opposite.

  I agree to forum rules 

» Online Users: 39
1 members and 38 guests
jordan1699
» HHC Sponsors
Closed Thread
 
Thread Tools Display Modes
  #1  
Old 01-26-2003, 12:37 PM
botzy botzy is offline
Member
 
Join Date: Jan 2003
Posts: 48
Send a message via AIM to botzy
PHP easy read layout.

Here is a neat way to seperate you page content and your site layout. It helps because you dont have to keep rewriting you code:

1. make your basic layout dont include you main content.
2. where ever you want your main contet to show up put this:

PHP Code:
<?
echo $yourcontent;
 
?>
3. save the layout file with this name "layout.php".
4. make a new file, name what ever the content will be. i.e. - "updates.php"
5. in that file put this code:

PHP Code:
<?
$yourcontent 
= <<<HTML




HTML;


include(
'layout.php');
?>
6. in between the <<<html and html; you put what ever content you wish to show up on that page.


Good Luck!
  #2  
Old 02-21-2003, 09:01 AM
Billy41684's Avatar
Billy41684 Billy41684 is offline
Super Moderator
 
Join Date: Oct 2002
Location: Houston, Texas
Posts: 2,154
Send a message via ICQ to Billy41684 Send a message via AIM to Billy41684 Send a message via MSN to Billy41684 Send a message via Yahoo to Billy41684
That would prbably make alot more sense to me if I knew PHP...
__________________
-Billy

"I am using Linux every day to up my productivity - so up yours!"

******** W A R N I N G ! *******************************
Linux should not be used by those under the influence of Microsoft.
May cause dizziness or vertigo. Consult your tech support before
using Linux. (note--after using Linux, you may notice extreme
discomfort when using Microsoft. Discontinue use of Microsoft.)
******************************* W A R N I N G ! ********
  #3  
Old 03-18-2003, 09:27 PM
BenRoshi's Avatar
BenRoshi BenRoshi is offline
Senior Member
 
Join Date: Mar 2003
Location: hi
Posts: 326
Send a message via AIM to BenRoshi
yeah i would definitly use php if i wasn't using iframes for a just as effective result. Just takes so many pages . well maybe later, thats a good tutorial though!
__________________
http://makubesu.ath.cx
hm... this side up... cool I can read upside down!
never critisize someone until you've walked a mile in their shoes.
because then you'll be a mile away, and have their shoes!
  #4  
Old 03-20-2003, 03:13 AM
XzAzX's Avatar
XzAzX XzAzX is offline
Senior Member
 
Join Date: Oct 2001
Location: Holland
Posts: 465
Send a message via ICQ to XzAzX
Yeah thats right, PHP does need a LOT of pages in that way, but I have a map called "includes", and that's where I put all my Included files

Then the code is just

PHP Code:
<?php
include('includes/page.php');
?>
It's an easy way to manage your information, and you'll only need PHP support for it
__________________
Get a life? Cool! Where can I download one of those?


[13:16] *** jerry was kicked by EggXeSS^mIRC (niet meer)
[13:16] *** EggXeSS^mIRC was kicked by CruSiS^Awej (Kick Protect)
[13:16] *** CruSiS^Awej was kicked by ChanServ (That user is protected.)


  #5  
Old 03-21-2003, 03:44 PM
hob goblin's Avatar
hob goblin hob goblin is offline
Senior Member
 
Join Date: May 2002
Posts: 499
Send a message via AIM to hob goblin
That's how I used to do it.

Now that I need to have a lot of PHP pages included and various other components I've found that I either need to:

1) Make a class/collection of functions in a file and include it on every page. Having a function to print the html before and another function to print the html after the content.

or

2) Make a template class. (Overkill for most things)
__________________
http://vexdev.com/forums/
programming help...art...everything important to geeks and artists
  #6  
Old 03-21-2003, 07:45 PM
element's Avatar
element element is offline
Super Moderator
 
Join Date: Aug 2001
Location: New Jersey, USA
Posts: 2,118
Or you could find an already made template class, because they are in most cases pretty complex to program yourself, and there are a ton of them out there.
  #7  
Old 04-13-2003, 03:08 AM
botzy botzy is offline
Member
 
Join Date: Jan 2003
Posts: 48
Send a message via AIM to botzy
Quote:
Originally posted by BenRoshi
yeah i would definitly use php if i wasn't using iframes for a just as effective result. Just takes so many pages . well maybe later, thats a good tutorial though!
As a note, this would use the same amount of pages(well one more) the only difference is that it is easier to edit and read your code. Same amount of pages...
  #8  
Old 04-29-2003, 05:47 PM
BenRoshi's Avatar
BenRoshi BenRoshi is offline
Senior Member
 
Join Date: Mar 2003
Location: hi
Posts: 326
Send a message via AIM to BenRoshi
um yeah its actually the same, except for oen little detail:
once one learns php, they start to put in message boards, chatrooms, guestbooks, and other stuff so you will have more pages
yeah I was dumb before, so ignore that last post, it is the same.
__________________
http://makubesu.ath.cx
hm... this side up... cool I can read upside down!
never critisize someone until you've walked a mile in their shoes.
because then you'll be a mile away, and have their shoes!
  #9  
Old 10-05-2005, 12:19 PM
Billy41684's Avatar
Billy41684 Billy41684 is offline
Super Moderator
 
Join Date: Oct 2002
Location: Houston, Texas
Posts: 2,154
Send a message via ICQ to Billy41684 Send a message via AIM to Billy41684 Send a message via MSN to Billy41684 Send a message via Yahoo to Billy41684
Now that I know PHP I can say this is not a good way to do it. At least its not the way I do it for many reasons.

What I ussually do it make a header.php page and a footer.php page. These pages are your layout and the content will go between them.

On my pages, like default.php I will just add the header at the top of the file and the footer at the bottom. That way you have your opening layout page, your content, then your closing layout page.

Example:

PHP Code:
<? include("header.php"); ?>

put your content crap here
(including tables or whatever html code you want)

<? include("footer.php"); ?>
This allows for even EASIER coding because its all not stored into one single variable.

Its also easy to update the code because each page has its own content, but if you change the header it changes on all pages, etc...
__________________
-Billy

"I am using Linux every day to up my productivity - so up yours!"

******** W A R N I N G ! *******************************
Linux should not be used by those under the influence of Microsoft.
May cause dizziness or vertigo. Consult your tech support before
using Linux. (note--after using Linux, you may notice extreme
discomfort when using Microsoft. Discontinue use of Microsoft.)
******************************* W A R N I N G ! ********

Last edited by Billy41684; 10-25-2005 at 09:21 AM.
  #10  
Old 10-05-2005, 03:03 PM
ShrineDesigns's Avatar
ShrineDesigns ShrineDesigns is offline
Moderator
 
Join Date: Dec 2002
Location: Seattle, WA
Posts: 1,322
Send a message via AIM to ShrineDesigns Send a message via Yahoo to ShrineDesigns
the phpbb template class works great, i use it in the developement of new php scripts/applications
  #11  
Old 10-05-2005, 03:27 PM
Billy41684's Avatar
Billy41684 Billy41684 is offline
Super Moderator
 
Join Date: Oct 2002
Location: Houston, Texas
Posts: 2,154
Send a message via ICQ to Billy41684 Send a message via AIM to Billy41684 Send a message via MSN to Billy41684 Send a message via Yahoo to Billy41684
What is the phpbb template class? Better yet, what is a template class? I'm a little dense when it comes to proper names of things.
__________________
-Billy

"I am using Linux every day to up my productivity - so up yours!"

******** W A R N I N G ! *******************************
Linux should not be used by those under the influence of Microsoft.
May cause dizziness or vertigo. Consult your tech support before
using Linux. (note--after using Linux, you may notice extreme
discomfort when using Microsoft. Discontinue use of Microsoft.)
******************************* W A R N I N G ! ********
  #12  
Old 10-05-2005, 06:21 PM
element's Avatar
element element is offline
Super Moderator
 
Join Date: Aug 2001
Location: New Jersey, USA
Posts: 2,118
I think phpbb uses a modification of fast template.

For large projects I use my own database (or flat file) driven template engine.

For small projects however, where setting up such a system is too time consuming the following method works extremely well.

Make 1 files and define the header/footer/other general templates in it as functions (or in a class if you want). IE:

PHP Code:
<?php

function html_header($title) {
    echo<<<HTML
<html>
<head>
<title>$title</title>
</head>
<body>
HTML;
}

function 
html_footer($year) {
    echo<<<HTML
<span>Copyright $year</span>
</body>
</html>
HTML;
}

?>
Then on each page all you have to do is,

PHP Code:
<?php
require_once('templates.php');

html_header('my page');

html_footer('2004-2005');
?>
This allows a basic template system to be more dynamic.

Last edited by element; 10-06-2005 at 05:35 PM.
  #13  
Old 10-05-2005, 08:34 PM
ShrineDesigns's Avatar
ShrineDesigns ShrineDesigns is offline
Moderator
 
Join Date: Dec 2002
Location: Seattle, WA
Posts: 1,322
Send a message via AIM to ShrineDesigns Send a message via Yahoo to ShrineDesigns
here is the phpbb template class (no comments)
Code:
<?php
class template
{
	var $_tpldata = array();
	var $files = array();
	var $root = "";
	var $compiled_code = array();
	var $uncompiled_code = array();

	function template($root = ".")
	{
		$this->set_rootdir($root);
	}
	function destroy()
	{
		$this->_tpldata = array();
	}
	function set_rootdir($dir)
	{
		if(!is_dir($dir))
		{
			return false;
		}
		$this->root = $dir;
		return true;
	}
	function set_filenames($filename_array)
	{
		if(!is_array($filename_array))
		{
			return false;
		}
		reset($filename_array);

		while(list($handle, $filename) = each($filename_array))
		{
			$this->files[$handle] = $this->make_filename($filename);
		}
		return true;
	}
	function pparse($handle)
	{
		if(!$this->loadfile($handle))
		{
			die("template->pparse(): Couldn't load template file for handle $handle");
		}
		if(!isset($this->compiled_code[$handle]) || empty($this->compiled_code[$handle]))
		{
			$this->compiled_code[$handle] = $this->compile($this->uncompiled_code[$handle]);
		}
		eval($this->compiled_code[$handle]);
		return true;
	}
	function assign_var_from_handle($varname, $handle)
	{
		if(!$this->loadfile($handle))
		{
			die("template->assign_var_from_handle(): Couldn't load template file for handle $handle");
		}
		$_str = "";
		$code = $this->compile($this->uncompiled_code[$handle], true, '_str');
		eval($code);
		$this->assign_var($varname, $_str);
		return true;
	}
	function assign_block_vars($blockname, $vararray)
	{
		if(strstr($blockname, '.'))
		{
			$blocks = explode('.', $blockname);
			$blockcount = sizeof($blocks) - 1;
			$str = '$this->_tpldata';

			for($i = 0; $i < $blockcount; $i++)
			{
				$str .= '[\'' .$blocks[$i]. '.\']';
				eval('$lastiteration = sizeof(' .$str. ') - 1;');
				$str .= '[' .$lastiteration. ']';
			}
			$str .= '[\'' .$blocks[$blockcount]. '.\'][] = $vararray;';
			eval($str);
		}
		else
		{
			$this->_tpldata[$blockname . '.'][] = $vararray;
		}
		return true;
	}
	function assign_vars($vararray)
	{
		reset($vararray);

		while(list($key, $val) = each($vararray))
		{
			$this->_tpldata['.'][0][$key] = $val;
		}
		return true;
	}
	function assign_var($varname, $varval)
	{
		$this->_tpldata['.'][0][$varname] = $varval;

		return true;
	}
	function make_filename($filename)
	{
		if(substr($filename, 0, 1) != '/')
		{
       		$filename = ($rp_filename = realpath($this->root . '/' . $filename)) ? $rp_filename : $filename;
		}
		if(!file_exists($filename))
		{
			die("template->make_filename(): Error - file $filename does not exist");
		}
		return $filename;
	}
	function loadfile($handle)
	{
		if(isset($this->uncompiled_code[$handle]) && !empty($this->uncompiled_code[$handle]))
		{
			return true;
		}
		if(!isset($this->files[$handle]))
		{
			die("template->loadfile(): No file specified for handle $handle");
		}
		$filename = $this->files[$handle];
		$str = implode("", @file($filename));

		if(empty($str))
		{
			die("template->loadfile(): File $filename for handle $handle is empty");
		}
		$this->uncompiled_code[$handle] = $str;
		return true;
	}
	function compile($code, $do_not_echo = false, $retvar = '')
	{
		$code = str_replace('\\', '\\\\', $code);
		$code = str_replace('\'', '\\\'', $code);
		$varrefs = array();
		preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs);
		$varcount = sizeof($varrefs[1]);

		for($i = 0; $i < $varcount; $i++)
		{
			$namespace = $varrefs[1][$i];
			$varname = $varrefs[3][$i];
			$new = $this->generate_block_varref($namespace, $varname);
			$code = str_replace($varrefs[0][$i], $new, $code);
		}
		$code = preg_replace('#\{([a-z0-9\-_]*?)\}#is', '\' . ((isset($this->_tpldata[\'.\'][0][\'\1\'])) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\') . \'', $code);
		$code_lines = explode("\n", $code);
		$block_nesting_level = 0;
		$block_names = array();
		$block_names[0] = ".";
		$line_count = sizeof($code_lines);

		for($i = 0; $i < $line_count; $i++)
		{
			$code_lines[$i] = chop($code_lines[$i]);

			if(preg_match('#<!-- BEGIN (.*?) -->#', $code_lines[$i], $m))
			{
				$n[0] = $m[0];
				$n[1] = $m[1];

				if(preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $n))
				{
					$block_nesting_level++;
					$block_names[$block_nesting_level] = $m[1];

					if($block_nesting_level < 2)
					{
						$code_lines[$i] = '$_' .$n[1]. '_count = (isset($this->_tpldata[\'' .$n[1]. '.\'])) ? sizeof($this->_tpldata[\'' .$n[1]. '.\']) : 0;';
						$code_lines[$i] .= "\n" . 'for($_' .$n[1]. '_i = 0; $_' .$n[1]. '_i < $_' .$n[1]. '_count; $_' .$n[1]. '_i++)';
						$code_lines[$i] .= "\n" . '{';
					}
					else
					{
						$namespace = implode('.', $block_names);
						$namespace = substr($namespace, 2);
						$varref = $this->generate_block_data_ref($namespace, false);
						$code_lines[$i] = '$_' .$n[1]. '_count = (isset(' .$varref. ')) ? sizeof(' .$varref. ') : 0;';
						$code_lines[$i] .= "\n" . 'for($_' .$n[1]. '_i = 0; $_' .$n[1]. '_i < $_' .$n[1]. '_count; $_' .$n[1]. '_i++)';
						$code_lines[$i] .= "\n" . '{';
					}
					unset($block_names[$block_nesting_level]);
					$block_nesting_level--;
					$code_lines[$i] .= '}';
					$m[0] = $n[0];
					$m[1] = $n[1];
				}
				else
				{
					$block_nesting_level++;
					$block_names[$block_nesting_level] = $m[1];

					if($block_nesting_level < 2)
					{
						$code_lines[$i] = '$_' .$m[1]. '_count = (isset($this->_tpldata[\'' .$m[1]. '.\'])) ? sizeof($this->_tpldata[\'' .$m[1]. '.\']) : 0;';
						$code_lines[$i] .= "\n" . 'for($_' .$m[1]. '_i = 0; $_' .$m[1]. '_i < $_' .$m[1]. '_count; $_' .$m[1]. '_i++)';
						$code_lines[$i] .= "\n" . '{';
					}
					else
					{
						$namespace = implode('.', $block_names);
						$namespace = substr($namespace, 2);
						$varref = $this->generate_block_data_ref($namespace, false);
						$code_lines[$i] = '$_' .$m[1]. '_count = (isset(' .$varref. ')) ? sizeof(' .$varref. ') : 0;';
						$code_lines[$i] .= "\n" . 'for($_' .$m[1]. '_i = 0; $_' .$m[1]. '_i < $_' .$m[1]. '_count; $_' .$m[1]. '_i++)';
						$code_lines[$i] .= "\n" . '{';
					}
				}
			}
			else if(preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $m))
			{
				unset($block_names[$block_nesting_level]);
				$block_nesting_level--;
				$code_lines[$i] = '}';
			}
			else
			{
				if(!$do_not_echo)
				{
					$code_lines[$i] = 'echo \'' .$code_lines[$i]. '\' . "\\n";';
				}
				else
				{
					$code_lines[$i] = '$' .$retvar. '.= \'' .$code_lines[$i]. '\' . "\\n";';
				}
			}
		}
		$code = implode("\n", $code_lines);
		return $code;
	}
	function generate_block_varref($namespace, $varname)
	{
		$namespace = substr($namespace, 0, strlen($namespace) - 1);
		$varref = $this->generate_block_data_ref($namespace, true);
		$varref .= '[\'' .$varname. '\']';
		$varref = '\' . ((isset(' .$varref. ')) ? ' .$varref. ' : \'\') . \'';
		return $varref;
	}
	function generate_block_data_ref($blockname, $include_last_iterator)
	{
		$blocks = explode(".", $blockname);
		$blockcount = sizeof($blocks) - 1;
		$varref = '$this->_tpldata';

		for($i = 0; $i < $blockcount; $i++)
		{
			$varref .= '[\'' .$blocks[$i]. '.\'][$_' .$blocks[$i]. '_i]';
		}
		$varref .= '[\'' .$blocks[$blockcount]. '.\']';

		if($include_last_iterator)
		{
			$varref .= '[$_' .$blocks[$blockcount]. '_i]';
		}
		return $varref;
	}
}
?>

Last edited by ShrineDesigns; 10-05-2005 at 08:38 PM.
  #14  
Old 10-06-2005, 09:09 AM
Billy41684's Avatar
Billy41684 Billy41684 is offline
Super Moderator
 
Join Date: Oct 2002
Location: Houston, Texas
Posts: 2,154
Send a message via ICQ to Billy41684 Send a message via AIM to Billy41684 Send a message via MSN to Billy41684 Send a message via Yahoo to Billy41684
wickedly brilliant! I'm gonna have to try this method.
__________________
-Billy

"I am using Linux every day to up my productivity - so up yours!"

******** W A R N I N G ! *******************************
Linux should not be used by those under the influence of Microsoft.
May cause dizziness or vertigo. Consult your tech support before
using Linux. (note--after using Linux, you may notice extreme
discomfort when using Microsoft. Discontinue use of Microsoft.)
******************************* W A R N I N G ! ********
Closed Thread

Thread Tools
Display Modes

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

Powered by vBadvanced CMPS v3.2.0
All times are GMT -4. The time now is 07:01 PM.