Page 1 of 2

CMS Template Engine

Posted: Thu Jun 01, 2006 4:05 pm
by William
Hello PHPDN,

I'm currenlty working with a client and he wants a control panel to manage his layouts. Well there is a problem in what he wants. He wants a CMS that can work with any layout he designs. Well I want to make my own "template" engine sort of like the Smarty engine where he can do {$TITLE_HERE} and I was wondering where I should start? I'm going through the Smarty engine now and the PHPBB template engine but I was wondering if there is some type of tutorial on making your own Smarty-like engine. Thanks

Posted: Thu Jun 01, 2006 4:51 pm
by PrObLeM
this may help, I haven't used it but it looks like a good start.

viewtopic.php?t=49079

Posted: Thu Jun 01, 2006 5:51 pm
by MrPotatoes
i like tiny but strong. it's what i'm using right now for my framework. i'll be making my own soon enough tho. i either need a licence where ic an sell my software of make my own. and seeing the over abundance of GPL and GNU style licences i'm gonna hafta make my own :D

give it a show. i suggest it

Posted: Thu Jun 01, 2006 5:55 pm
by Christopher
MrPotatoes wrote:i either need a licence where ic an sell my software of make my own. and seeing the over abundance of GPL and GNU style licences i'm gonna hafta make my own :D
GPL in no way limits your ability to sell your software -- it may make some requirements that you include the source with your product, but since you got that code for free you should anyway.

Posted: Thu Jun 01, 2006 6:18 pm
by William
Is there some kind of tutorial or example on a code that would make a .htm file that had {$PAGE_TITLE} in the html file that I could make PHP take that and replace it with the text "Welcome to my site?" or does anyone know where I should start to do something like this?

Posted: Thu Jun 01, 2006 6:32 pm
by daedalus__
A dynamic title, like in the title bar? Or are you trying to figure out how to output a variable to the page?

Note: .htm and .html files won't get parsed by php by default, the files have to be named .php

Code: Select all

$page_title = "Welcome to my site?";
echo $page_title;
??

Posted: Thu Jun 01, 2006 6:56 pm
by William
No I understand how to varibles. :), I'm wanting to make a script that took {$SITE_TITLE} out of a html or lets say .tpl files in my /themes/ folder and the PHP script read it and inserted the data from the varible $SITE_TITLE. Basicly I'm not sure if you have ever used PHPBB but when making a theme they allow the theme designers to use {$VARIBLES} into there .tpl files. My PHP script is going to take there .tpl files and generate the page. So basicly I could use multiple themes with the same PHP script and it doesn't take another PHP coder to make layouts for it. aka like the Smarty engine.

Posted: Thu Jun 01, 2006 8:34 pm
by RobertGonzalez
Take a look into my signature and click on the AKA Panama Jack's TemplateLite link. It is an exceelent templating system based on Smarty without all the fluff and stuff.

Posted: Thu Jun 01, 2006 11:03 pm
by Christopher
There are several common ways to do templates in PHP:

1. Use embeded <?php ?> tags and include the template. The result can be captured with output buffering if desired.

2. Load the template into a string and have the variables in the template expanded by PHP string parsing capabilities.

3. Use str_replace()/preg_replace()/etc. to replace tags within a template loaded as a string.

4. XML/XSL/XLST translation.

For #1 and #2 you might want to check into the expand() function.

Posted: Thu Jun 01, 2006 11:16 pm
by RobertGonzalez
William wrote:No I understand how to varibles. :), I'm wanting to make a script that took {$SITE_TITLE} out of a html or lets say .tpl files in my /themes/ folder and the PHP script read it and inserted the data from the varible $SITE_TITLE. Basicly I'm not sure if you have ever used PHPBB but when making a theme they allow the theme designers to use {$VARIBLES} into there .tpl files. My PHP script is going to take there .tpl files and generate the page. So basicly I could use multiple themes with the same PHP script and it doesn't take another PHP coder to make layouts for it. aka like the Smarty engine.
Why not just use the phpbb template.php code?

Posted: Fri Jun 02, 2006 1:37 pm
by William
Because I have always been big on doing stuff from scratch so maby I will understand it better. Thank you for all the help! I'll look into everything! Thanks again.

Posted: Fri Jun 02, 2006 1:41 pm
by William
arborint wrote:There are several common ways to do templates in PHP:

1. Use embeded <?php ?> tags and include the template. The result can be captured with output buffering if desired.

2. Load the template into a string and have the variables in the template expanded by PHP string parsing capabilities.

3. Use str_replace()/preg_replace()/etc. to replace tags within a template loaded as a string.

4. XML/XSL/XLST translation.

For #1 and #2 you might want to check into the expand() function.
expand() function?

Posted: Fri Jun 02, 2006 1:45 pm
by Roja
William wrote:
arborint wrote: For #1 and #2 you might want to check into the expand() function.
expand() function?
I think (please correct me if I'm wrong, arborint) he meant the explode() function.

Posted: Fri Jun 02, 2006 1:47 pm
by William
Ah that is what I thought, thanks. :)

Posted: Fri Jun 02, 2006 2:08 pm
by MrPotatoes
arborint wrote:
MrPotatoes wrote:i either need a licence where ic an sell my software of make my own. and seeing the over abundance of GPL and GNU style licences i'm gonna hafta make my own :D
GPL in no way limits your ability to sell your software -- it may make some requirements that you include the source with your product, but since you got that code for free you should anyway.
yeah, your right, but if i want to keep something closed source then i can't do it under GPL. i guess i should have wrote that better