hmm your templating systems all seem to be very complicated!!
what i do is just have a template file eg "template.html" with values like {main} for the main part {links} for the menu etc.etc.
and i put this code with it, if this looks a bit weird its cause i just copyed it from a script of mine
Functions.php

function make_skin($links, $main, $title){
//find skin
global $copy, $noone_menu;

$template1 = implode(" ", file("template/template.html"));

//make skin
$template = str_replace("{nav}", "$links", $template1);
$template = str_replace("{title}", "$title", $template);
$template = str_replace("{main}", "$main", $template);
echo "$template";
}

index.php

include "Functions.php";
$main = "<font>some html</font>";
$title = "hello";
$links = "<a href=\"somefile.php\">click here</a>";
make_skin($links, $main, $title);

and its done!! enjoy!

    I'm a little late on this topic, but here my two cents.

    I've been working on CMS for a while too Tekime. I've got one site I maintain. I use this site to test my own script and just about everyone else's. I've used both FastTemplate and Smarty and didn't like either. Here's why.

    Now some are going to think I'm being nasty, but I have nothing against the people who use Smarty or those who created Smarty. Personally, I perfer to not even to open my mouth about it as I'm an introvert. But, I find it difficult to keep my mouth shut when logic is being toss out like the trash on Wednesday. So with that said. Let's pick on Smarty.

    Directly from the website:

    Smarty is a template engine for PHP. Smarty provides your basic variable substitution and dynamic block functionality, and also takes a step further to be a "smart" template engine, adding features such as configuration files, template functions, variable modifiers, and making all of this functionality as easy as possible to use for both programmers and template designers.

    "Smarty is a templating engine for PHP." What? PHP is a templating engine. So, why do we need Smarty? Any thing they can do, PHP is doing for them and could do faster. If smarty was a standalone programming/script language I would have no problem with it. But, it's not. It's sitting on top of a more powerful template engine that does everything it does and more.

    Smarty provides "basic variable substution." What's so basic about it? They're parsing HTML for they're variables! Isn't that what PHP is already doing! Or have we all forgotten that everything outside of these "<?php ?>" is HTML? So which is more basic?

    1. <?php echo $title; ?>
    
    or 
    
    2. {$title}.

    Want to guess which one is faster?

    Smarty provides "dynamic block functionality." Dynamic block's? Hold on, templates are suppose to seperate logic from layout. What's with these dynamic block's then? Here you are putting logic back in the templates. No matter whether you call them "sections" or "for..next loops" they're still logic constructs! It's should go without saying that PHP will whip Smaty's ass in any loop. (See above code and think about it.)

    Smarty provides "configuration files, template functions, variable modifiers, and making all of this functionality as easy as possible to use for both programmers and template designers." Hold on doesn't PHP provide all that and more? How is it easier, your making me learn a new programming language called Smarty! And the template guy was warried when I mentioned PHP, now he's wondering what the heck "Smarty" is.

    You know what the problem is? It's not Smarty, it you and me. I have no problem understanding either HTML or PHP. I can intermingle them and still understand them. They both make sense to me. But, not everyone is as luck. That poor template designer sure doesn't want to learn a server side scripting language. The template designer isn't a programmer, so we have to help him out. How can we help him? Let's keep it simple and seperate the logic from the layout. We can do that without Smarty and we can do it better.

    We can create powerful templates, limiting ourselves to simple PHP statements. Keep the logic in a .php file and the layout in an .html file. If it takes more than one PHP statement it doesn't belong in the template file. If it involves more than an echo or a simple "if" statement than it doesn't belong in the template file.

    It should be as simple as one, two, three.

    1. Include any libraries you need.
    2. Create the variables.
    3. Include the template file.

    That simple. Click, you got a web page.

    Simple template example.

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <META HTTP-EQUIV="Expires" CONTENT="Sat, 23 Nov 2002 01:28:44 GMT">
    <TITLE><?php echo $site_title; ?><?php if($page_title){echo ' - '.$page_title;} ?></TITLE>
    <META NAME="keywords" CONTENT="<?php echo $site_keywords; ?>">
    <META NAME="description" CONTENT="<?php echo $site_description; ?>">
    <META NAME="author" CONTENT="Buddha">
    <META NAME="ROBOTS" CONTENT="ALL">
    <script language="javascript" src="common.js" type="text/javascript"></script>
    <link title="Contemporary" href="common.css" type="text/css" rel="StyleSheet">
    </head>
    <body text="#000000" bgcolor="#ff0000">
    <?php echo $content; ?>
    <br>
    <?php echo $counter; ?>
    </body>
    </html>

    Now you can fill in those variables anyway you want. Get them from a database, flat file, or embed them in the script. But, the template designer doesn't need to know how you do it. All he needs to know is anything in between "<?php" and "?>" is off limits.

    I'm the less worthy among us to be giving anyone advice on programming. However, I think there's some logic in my statements. Please give them some consideration.

    Let the flaming begin...

      Buddha443556, i totally agree whats the point of typing rediulas amouts of commands when you just go {main} and have a simple str_replace function, by using built in functions like smarty your not saving yourself any time, make your own skinning system, or use mine!

        Thanks Duey. If nothing else doing it yourself sure is more fun!

        [EDIT DO TO INTUITIVE USER AT KEYBOARD. I can read something three time and unconsciously insert the missing word each time.]

          I totally agree with Buddha.

          Templates are meant to "separate logic from presentation". Take a look at Smarty: it has foreach loops, if-else constructs, even functions! Are they insane or something, functions in a template language?!?

          I cannot believe that the people who write Smarty do not realize that they are in fact creating their own programming language on top of PHP, which is meant as a templating language! If Smarty continues this way, in a year I'm sure there will be a syntax like {mysql_connect host="localhost"} for connecting to databases and stuff..

          The sentence "separate logic from presentation" is mis-used and misinterpreted so many times. People think that if you put {tags} in a separate file and then write up some AbracadabraTemplate class, which replaces these {tags} with variables, you "separate logic from presentation", whatever they think that may be. You use PHP code to assign variables to your templates, which means that the 'logic' (PHP) is coupled to the presentation (templates)!

          It should be "separation of presentation logic from business logic". In my opinion, even templates are allowed to have simple presentational logic, such as if-else constructs. For example, {if $price < 1} Wow this is cheap {/if} would be perfectly valid.

          But then again, why would we use a templating system, like Smarty for example when PHP itself is basically (note the 'basically', I am not saying it can not be used for anything else) a templating language?

          If you're interested on reading more on this, try this thread over at another forum.

            I would have to argure, php is not a templating language, yes it can do it, but its less than 1% of what php does in total. every language is a templating language in your mind?

              Man, did you read my post closely? I said PHP itself is basically (how much do I need to stress this word 'basically'?) a templating language. Go ask the creators: PHP/FI was originally meant as something that could display information from business logic written in C programs on HTML pages.

              Don't think that when I say PHP is basically a templating language, I'm saying it is not good for anything else. I use PHP for complete web applications and I love the way it works. All I am saying is that there is no point in creating a templating system like Smarty on top of PHP, when PHP can do the exact same.

                I agree, sorry its late, going to bed :rolleyes:

                  by poseidix:
                  {if $price < 1} Wow this is cheap {/if} would be perfectly valid.

                  I think that's a good example (even if it's in Smarty) of seperating the logic and the layout. I don't think it would be any harder to explain to a template designer than this <?php if($price < 1){ ?><!-- Template Designer Note: low price indecator here text or graphic--><?php } ?>. Once you explain it to the designer, he might come back and tell you, "we need to change that logic." People don't need help finding the cheap items they need help finding the items we have overstocked. Anyway, the point is whatever way you do it communication is important.

                  It would be great if you could just hand a template over to a designer and forget about it. But, it doesn't work that way. Whether we use Smarty or PHP we'll still need to collaborate with the designer. The more dynamic the page the more this becomes important.

                  I'm all for using templates. I even use them to create result tables, like Smarty, but it's strictly PHP. If a designer want to change the layout there's three templates he can play with header, row and footer. Practicing the seperation of logic and layout does two thing creates better looking scripts and better looking layouts. I don't have to worry about the layout any more I can change that when I'm done with the logic.

                  [EDIT: Do to intuitive at keyboard.]

                    yipes I wish I had some more time to dig into this, but I'm at work right now...

                    I can appreciate and understand you buddha, duey and poseidix. BUT, I don't think usnig PHP as the templating language makes any sense. I have a much more complex layout than "header, row, footer". I want the designer to have control over the display of widgets which I embed into my layout, fractions of my layout, et cetera. I don't want my CMS to look like Nuke, basically.

                    My main concern here is not how to display a single variable, or a small array of variables, but how to display complex datasets or variable lengths and keep it simple and safe for the deisgner, AND for me.

                    Maybe you can diminish this for the newbie in me, but how can it get easier OR safer than something like this:

                    <!-- BEGIN DYNAMIC BLOCK: user_row -->
                    <tr>
                        <td>{username}</td>
                        <td>{firstname}</td>
                        <td>{lastname}</td>
                    </tr>
                    <!-- END DYNAMIC BLOCK: user_row -->
                    

                    For those of you saying PHP is entirely effective and safe as a templating language, how can I accomplish the above code without a template class? Remember that each row is derived from a multi-level array of unknown length. And if the point is to keep the logic out of the template, how could I accomplisht he above without a bunch of foreach mumbo jumbo?

                    Sorry if I was curt or sloppy, I'ma bit busy but I'll be back to read the details later 😃

                      I have no problem with the use of templates or template classes/libraries. I have one of my own, I'm very fond of it.

                      First all of my templates are stored in a database and access by name. This is just my preference, you could use files.I could rewrite 'template_get' so they're altogether in one entry and broken up in template_get. However, I have found this to be more efficient. I have one function that parses templates and it does it recursively too.

                      function template_parse($parse_template, $parse_variables){
                      	extract($parse_variables);
                      	while(stristr($parse_template,'<?php ')){
                      		ob_start();
                      		eval("?>" . $parse_template . "<?php ");
                      		$parse_template = ob_get_contents();
                      		ob_end_clean();
                      	}
                      	return $parse_template;
                      }

                      Here's a function that display a result table:

                      function show_item(){
                      	global $tcm, $error, $PHP_SELF;
                      
                      // get the templates	
                      $templates['show_header'] = template_get('tcm_list_item_header');
                      $templates['show_footer'] = template_get('tcm_list_item_footer');
                      $templates['show_row'] = template_get('tcm_list_item_row');
                      $templates['admin_page'] = template_get('admin_page');
                      
                      $list_name = $_GET['list_name'];
                      if(preg_match('/\W/',$list_name) || empty($list_name)){
                      	error_page($error['bad_list_name'], $templates['admin_page']); 
                      }
                      if(!list_exist($list_name)){
                      	error_page($error['list_not_found'], $templates['admin_page']); 
                      }
                      
                      $var['list_name'] = $list_name; 
                      
                      $limit	= $tcm['template_results_per_page'];// number of records per page
                      // check for a limit or leave it alone
                      if(isset($_GET['limit']) && is_numeric($_GET['limit'])){
                      	if($_GET['limit'] <= 100){
                      		$limit	= $_GET['limit'];
                      	}
                      }
                      
                      $curpage = 0;// current page of records to display
                      // check for an offset or leave it 0
                      if(isset($_GET['page']) && is_numeric($_GET['page'])){
                      	if($_GET['page'] >= 0){
                      		$curpage = $_GET['page'];
                      	}
                      }
                      
                      // get the number of records
                      $numrec = list_item_count($row['name']);
                      
                      // calculate the number of pages
                      $numpage=intval($numrec / $limit);
                      if ($numrec % $limit) {
                      	$numpage++; // add one page if remainder
                      }
                      
                      $offset = $limit * $curpage;
                      // make sure offset is less than number of records
                      if($offset > $numrec){
                      	$curpage = $numpage - 1;
                      	$offset = $curpage * $limit;
                      }
                      
                      // get the table header and add it to the content
                      $var['content'] = $templates['show_header'];
                      
                      $list_id = list_id($list_name);
                      // get the rows to display
                      $query = 'SELECT * FROM `list_item`'
                      	.' WHERE `pid` = '
                      	.$list_id
                      	.' ORDER BY `name` ASC'
                      	.' LIMIT '
                      	.$offset
                      	.', '
                      	.$limit;
                      $result = db_query($query, $tcm['db_link']);
                      
                      // add the rows to the content
                      while($row = db_fetch_assoc($result)){
                      	$row['list_name'] = $list_name;
                      	$var['content'] .= template_parse($templates['show_row'], $row);
                      }
                      
                      // get the footer and add it to content
                      $var['content'] .= $templates['show_footer'];
                      
                      $var['chain'] = page_chain(
                      	$PHP_SELF.'?op=show_item&limit='.$limit.'&page=',
                      	$curpage,
                      	$numpage);
                      
                      // get the page template and display page
                      echo template_parse($templates['admin_page'], $var);
                      }

                      This is a dynamic page. Notice the page uses four templates. Three of the templates are used for creating the table: $templates['show_header'],$templates['show_row'] and $templates['show_footer']. The last is the $templates['admin_page'] witch contains that dreadful <?php $content; ?> statement. Also notice the error_page uses templates too. Static pages are ridiculously simple. But as you can see one simple function template_parse is all there is to it.

                      See any HTML?

                        Buddha, thanks for sharing your work with us. Honestly though, I don't want to invest the time into making my own templating library. I doubt I am anywhere near as knowlegeable about PHP as yourself, so "whipping up" some templating functions to suit my CMS would be a lot more work than I can manage now.

                        One thing I'm wondering though, do you think the speed advantage has anything to do with the templates being stored in a db? Also, how do you manage your templates, did you build an interface for the designer to modify them, or use phpMyAdmin, etc.?

                        I think with some work I could transform your method into a faster alternative for my project, but I would like my templates stored in flat files for the time being. Also I would definitely need more control over the execution of say 'show_item', or I would end up needing a multitude of functions to piece together templates of varying formats.

                        Right now most of my pages are broken down into:

                        • header

                        • page header

                        • margin left top

                        • margin left bottom

                        • margin right top

                        • margin right bottom

                        • footer

                        And I have functions like guiShow_fullheader() to parse numerous plates using my template class. This way I can show my page in many ways, and add new elements as I choose with a corresponding guiShow function. I also have a 'widget' library for parsing widgets - which are various templates like login boxes, date, users online, et cetera.

                        It might not be super fast, but it flexible and easy to implement. At any rate, Smarty was really working against what I wanted; for the time being I'm using class.rFastTemplate and until I have the time (or more importantly skills) to write my own templating, I'd like not to rewrite the wheel 🙂

                        Thanks again for posting.

                          i store my template in an html file just using {main} then replacing it with the content. sometimes i would use mysql if theres lot of it which does speed up proccessing time as its not loading all the content

                            To tell you the truth I never really measured the how fast the pages were produced. Never cared. It was nice of mordred to do it though. I knew it was faster. It was fast even when I was orginally using flat files, too. But, it's the ease and flexible that told me I was on the right track. That I can't be measure.

                            I was using phpMyAdmin, which worked ok. The code in the examples are from the administration pages I've been working on. I was just tweeking the layout before I came here. Got a couple of more things to add, but eventually I should be able to input and execute scripts from the admin page. After all, template_parse does PHP. My goal is a tool that will allow me to maintain multiple sites.

                            It's sounds as though your invest in rFastTemplates, which isn't a bad thing if it's working for you. I hope you give it a try, implementing your own template system using pure PHP. I think you would find it simpler than you think. However, I'm planning to start a sourceforge project, so you'll be able to see what I've done and whether you can make the switch.

                            [edited do to groggy coder at keyboard]

                              Write a Reply...