Click to See Complete Forum and Search --> : Template Engines


infestedarch0n
07-29-2006, 05:39 PM
I developed this template engine as an alternative to Smarty. I wrote up some documentation and I plan on making it a brilliant project to suit many programmer's needs, without sacrificing speed, and overcomplication. I would like suggestions if possible. I was considering putting this in code critique but suggestions on how to write a better guide or even additional feature suggestions would be helpful.

The guide and code is here: http://code.divineaspirations.net/chip

Thanks.

halojoy
07-30-2006, 08:23 AM
hi
There might be some that wants to use template engines
and there might be situations where this is a good choice.
Smarty is most used, but there are other both more simple and faster.

Personally I dont use template engines.
I dont have any need for it, as I can use, in my opinion,
better ways with less code.

Here is such an example.
A one page 'template engine',
tpl_admin_index.php<?php
/////
$left = <<<LEFT
<a href="?act=editpage">Edit Page</a><br>
<a href="?act=newpage">Create New Page</a><br>
<a href="?act=delpage">Delete Page</a><br>
LEFT;
//
$header = <<<HEAD
ADMIN :: $atitle
HEAD;
//
$footer = <<<FOOT
copyright by me
FOOT;
//
$style = <<<STYLE
body {background:#bf9f8f; text-align:center;}
a {color:#0066cc;text-decoration:none}
a:hover {color:#cc0066;text-decoration:underline}
#wrapper{width:900px; margin-left:auto;margin-right:auto; background:#efefef;
border:1px solid #666666;text-align:left;}
STYLE;
/////
?>
<html><head>
<title><?php echo $sitename ?> :: Admin</title>
<style text/css><!--
<?php echo $style ?>
--></style></head>
<body><div id="wrapper">
<div id="header"><?php echo $header ?></div>
<div id="left"><?php echo $left ?></div>
<div id="main"><?php echo $main ?></div>
<div id="footer"><?php echo $footer ?></div>
</div></body></html>

infestedarch0n
07-30-2006, 02:40 PM
Exactly, that's what makes this world so great: not everybody prefers the same thing! I think that's wonderful, and without it we'd all probably just be using Windows.

Anyway, if I may, my method is not so far off from yours. Of course the template engine could be made easier, however, I'd like to present how I'd write your code.

<parser:new name="default">
<html><head>
<title>{$sitename} :: Admin</title>
<style text/css><!--
<parser:link name="style">
--></style></head>
<body><div id="wrapper">
<div id="header"><parser:link name="header"></div>
<div id="left"><parser:link name="left"></div>
<div id="main"><parser:link name="main"></div>
<div id="footer"><parser:link name="footer"></div>
</div></body></html>
</parser:new>
<parser:new name="left">
<a href="?act=editpage">Edit Page</a><br>
<a href="?act=newpage">Create New Page</a><br>
<a href="?act=delpage">Delete Page</a><br>
</parser:new>
<parser:new name="header">
ADMIN :: {$atitle}
</parser:new>
<parser:new name="footer">
copyright by me
</parser:new>
<parser:new name="style">
body {background:#bf9f8f; text-align:center;}
a {color:#0066cc;text-decoration:none}
a:hover {color:#cc0066;text-decoration:underline}
#wrapper{width:900px; margin-left:auto;margin-right:auto; background:#efefef;
border:1px solid #666666;text-align:left;}
</parser:new>And then the code$gui->variables['sitename'] = $sitename;
$gui->variables['atitle'] = "This page's title";

$gui->output_template( "default" );Which really wasn't that much of a pain.

I do realize that "$main" was not provided in your example probably because you mean it's elsewhere. The current best way to solve this problem with the template engine is to create a header in a footer in separate templates, and then link them. However, I'm not sure if I agree with this method. Perhaps if I get a lot of feedback and people opt to use the template engine, version two will have a template aliasing system.

So the above example could work by doing this:$gui->variables['sitename'] = $sitename;
$gui->variables['atitle'] = "This page's title";

$gui->alias_template( "main", "sub_page_template" );

$gui->output_template( "default" );I hope you get what I mean.

Thanks for the reply.