Solved

php template system

Posted on 2003-11-02
7
310 Views
Last Modified: 2006-11-17
I am looking for a php template system to use with my application. I realize that the ideal solution would be to create my own but I am fairly new to php and I feel I would probably end up doing more harm then good performance wise so I decided to go with a 3rd party solution.

I have been looking over the various "popular" template systems like smarty,quick template,phemplate,fast template... but have yet to find one that really suits my needs which are.

1.) Simple to use (I don't want to have to deal with config files and extension classes and other bloated features a.k.a smarty_ware) I just need the  basics along with database support.

2.) Fast (not much else I can say except it has to be faster then Fast Template)

3.) Has a fair amount of documentation / examples to learn from (would rather not spend 3 days trying to "guess" how the system works)

Out of all of the systems I have looked at it would appear that phemplate comes closer to meeting my needs then any of the others but there is not alot of  documentation on it and I have no idea if it has database support or not so maybe if someone could just enlighten me on these things then I could use it but if not then what else could I use ???

Thanks for all replies in advance.


 
0
Comment
Question by:ezpete
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 4

Expert Comment

by:lokeshv
ID: 9666220
check patTemplate may be this is wat u need..

a nice article on it on devshed..

http://devshed.com/Server_Side/PHP/patTemplate/patTemplate1/page1.html

hope this helps.

Lk
0
 

Author Comment

by:ezpete
ID: 9666796
That was another one I thought about using but have been unable to find any benchmarks on it. Has anyone used it and if so how does it compare to the other systems.
0
 

Author Comment

by:ezpete
ID: 9666954
I just went to the pat template website and noticed that the project has not been updated in some time and on their forums alot of people are complaining about speed issues and lack of updates so I think I will have to pass on this one.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:red010knight
ID: 9668740
Actually PHP has a built in function that makes it easy for templates to be used.

All your PHP code goes in one file with the use of
eval() which you can get walked through at www.php.net

and then in a HTML file you just have to use $codeword to be replaced with the dynamic info you wnat.

My preference is to set up strings of data to be fed in to the variable. So like for a dynamic table the variable would be set up something like:

$TD_START="<td>";
$TD_END="</td>";
$TR_DESC="<td colspan=\"3\"><i>Description</i>: ";
$TR_START_ODD="<tr bgcolor=\"#CCCCFF\">";
$TR_START_EVEN="<tr bgcolor=\"#EEEEFF\">";
$TR_TD_END="</td></tr>";
$LINK_OPEN_START="<a href=\"";
$LINK_OPEN_END="\">";

$stringToPrint="";
while blah do blah
$stringToPrint.=$TR_TD_START . dynamicVar . $TD_END;
$stringToPrint.=$TD_START . $LinkData_open . fileName . $LinkData_close . $TD_END;
$stringToPrint.=$TD_START . dynamicData . $TD_END;
$stringToPrint.=$TD_START . dynamic data . $TR_TD_END;
$stringToPrint.=$TR_TD_START . $TR_DESC . dynamicdata . $TR_TD_END;
end while loop

the above code is part pseudo so as to give an example but it is what I use for my work pages. So that I can let people do all they want to the template files and not have to worry about PHP errors showing up in the backend files. Makes for updating the look and feel of pages a whole lot easier too.

And this is all you need at the end of your PHP code to do the evaluating:

$useFile=file($thisPage);

//format output
foreach ($useFile as $line) {
  $str = $line;
  // add slashes to prevent premature string escaping
  $str=addslashes($str);
  // evaluate the code (note the value is returned in the function)
  eval("\$str = \"$str\";");
  // remove the slashes you used to protect your string during parsing
  $str=stripslashes($str);
  echo $str;
}

Hope this helps and happy coding
Red010Knight
0
 

Author Comment

by:ezpete
ID: 9670185
Thanks for the code but I also need support for databases and such which I your code will not work with but thanks again.
0
 
LVL 3

Accepted Solution

by:
red010knight earned 100 total points
ID: 9670638
::blink blinks::
Looks at the code,
My code interfaces with the database at my work. What database are you using that php won't support? or do you not understand how to add database data to the above code?

The dynamicVar,dynamicData and a few other variables is where your database vars would go to put data in.
The previous post is strictly for the code setup to give you and understanding of how I handle events such as dynamic tables:
    while($blah=$mysql_fetch_array($result)){
can be inserted in the previous post at:
  while blah do blah
with a little bit of editing it works seamlessly and with no errors that I've yet discovered.

Good luck with your page, if you need further help on database queries and putting them in a page like the above, I will do my best to help.

Red010Knight
0
 

Author Comment

by:ezpete
ID: 9675157
I decided to use phemplate but since you provided your own code I gave you the points anyway so thanks for the effort.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question