Re: templating

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I just wanted to add that Richards technique is a good way to go.
I often use something very similar, the only difference being that I
make the head() and foot() function methods in class (an instance
of the class being created by the global include file for the given site
e.g:

class Page
{
	function Page() { /* setup page  */ }
	function head() { /* show header */ }
	function foot() { /* show footer */ }
}

I find that the class has all the benefits of the
structure Richard proposed with the added benefit (my opinion :-)
that you can store page related data in the global 'Page' object
as and when you need to and use that data when you do the output...
the net result means you may probably end up polluting the global
space with less variables.

Richard Lynch wrote:
> On Thu, June 22, 2006 6:10 am, Ryan A wrote:
>> He just needs maybe 5 template
>> pages, same pages, different color.
> 
> For something THIS simple, I truly believe you are Better Off (tm)
> with a simple head() and foot() function in a globals.inc file:
> 
> function head($title = "My Site", $bgcolor = '#ffffff'){
> ?>
> <!DOCTYPE ...>
> <html>
>   <head>
>     <title><?php echo $title?></title>
>   </head>
>   <body bgcolor="<?php echo $bgcolor?>">
> <?php
>   }
> 
>   function foot(){
> ?>
>   </body>
> </html>
> <?php
>   }
> ?>
> 
> Your header and footer are now in one "template-like" file which makes
> it easy to match up tags.
> 
> And the 5 pages will look like:
> 
> <?php
>   require 'globals.inc';
> 
>   head('Page One', '#fcfcfc');
> ?>
> <p>Page One specific content here</p>
> <?php
>   foot();
> ?>
> 
> 
> The reason I prefer this to header/footer includes, is that it's too
> easy to mess up closing tags in footer/header out of sync with
> separate files, but with one file, they're right there and a decent
> HTML editor will pick them out for you.
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux