CMS Template Engine

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

CMS Template Engine

Post 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
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

this may help, I haven't used it but it looks like a good start.

viewtopic.php?t=49079
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post 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?
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post 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;
??
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post 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.
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post 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?
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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.
User avatar
William
Forum Contributor
Posts: 332
Joined: Sat Oct 25, 2003 4:03 am
Location: New York City

Post by William »

Ah that is what I thought, thanks. :)
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post 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
Post Reply