Forum Moderators: coopster

Message Too Old, No Replies

php template systems

         

ayushchd

7:56 pm on Nov 15, 2007 (gmt 0)

10+ Year Member



Hi all!

I just wanted to know whether it is a good practice to use template systems...if not, what are the other ways we can make our code easier to read by separating html from php?

mooger35

9:33 pm on Nov 15, 2007 (gmt 0)

10+ Year Member



I use one so changes are much much easier to make.

I believe jatar posted something like this which got me going.

// includes/template.php
<?php
include 'includes/header.php';
include 'includes/content.php';
include 'includes/footer.php';
?>

// includes/content.php
<div id="content"><!-- main content goes in here -->
<?php include $content;?>
</div><!-- end content -->

// index.php
<?php
$content = "includes/content/main.php";
include "includes/template.php";
?>

// includes/header.php
<html>
<head>
<title></title>
</head>
<body>

// includes/content/main.php
<p>put content here</p>

// footer.php
</body>
</html>

ayushchd

6:06 am on Nov 17, 2007 (gmt 0)

10+ Year Member



thnx...but what i was asking is that is it a good practice to use template systems?

phparion

7:32 am on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



template system, basically, helps you keep your information processing code separate from the design. You can reuse your code easily in many similar projects. You can change the design very easily too. Did you check smarty template system?

I personally, ehhhh! could be controversial on this, don't like template based system. I think it makes easy things look more difficult. I rely on PHP system that I have made during my programming years. It is based on OOP.

ayushchd

7:49 am on Nov 17, 2007 (gmt 0)

10+ Year Member



How does it make easy things look more difficult?
What kind of system have you made?

PHP_Chimp

6:33 pm on Nov 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Like many things templates seem to be something that everyone 'must have', because they are cool (see my rant at the bottom).
One of the sites that I run is a training providers site. So all of the pages about courses have an identical structure. So it seems sensible to use a template for all of those. However the pages that are not there for courses are not template based, as these are not identical from page to page, so it seems silly to have a template that has a huge switch statement to redesign it for 50 different pages...just code them the old fashioned way as it is actually easier to sort out.
I do however have an included piece of code that prints the navigation bar and other bits that remain constant on all of these not template based pages.

To make it easier to read php move as much of your php into an included file. So I have an included file that has a function to print the nav bar, then you just call it as echo nav(); at the bottom of the html.

<rant>
Cool...
like xhtml is...yet how many people are serving xhtml as application/xhtml+xml, its all text/html.
Ajax was cool, everyone used it...for loading images that were not needed and other stupid stuff just to show how great a web developer they were.
Templates are cool, if you dont use them then you are so 2000...

All of these things have there place, but you need to decide if your use is because this is the best thing for you...or just cos its cool.
</rant>
Im going to sit outside and look at the moon to calm down ;)