template system

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

Post Reply
jaymoore_299
Forum Contributor
Posts: 128
Joined: Wed May 11, 2005 6:40 pm
Contact:

template system

Post by jaymoore_299 »

I want to be get a template system going where it looks something like this:

html code

{php,
insert custom
data}

end of html

I want the contents within the bracket to be replaced by whatever I want, and everything else to be the same.
I want to be able to send specific variables within, such as:
{type NEWS
color BLUE
font COURIER
}
,which would return news article in color blue with courier font.
After creating the template, it would be saved as an html file with no php code in it.

What's the best way to do this?
Should I use <?php (variables) >? Is there any issue with using <?PHP ?>
multiple times throughout the page?
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

... what you want is XML ...
searching the API or google will find you a quick example to get you up and running in 30min.

SimpleXML is really easy, if that is not available use the XML-parser and a function to make it easily read (can be found on php.net usercontributions).
Last edited by Syranide on Fri Jun 03, 2005 2:00 am, edited 1 time in total.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Get a closer look on what Mambo did, does.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

ol4pr0 wrote:Get a closer look on what Mambo did, does.
Mambo doesn't use templating.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

patrikG wrote:
ol4pr0 wrote:Get a closer look on what Mambo did, does.
Mambo doesn't use templating.
The do seem to use a Template View pattern and even Helpers although the use of scriptlets is probably obsene to some people.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

If there was a degree of consistency in their use of design patterns, plus a seperation of logic and view, it would be fantastic. Mambo's DB-class for example has some nice ideas & they seperate content and view, but not logic and view. And that's what I find most taxing: their constant mix of logic and view. Thus, while they are, by name, using "templates", they are not implementing the concept and are loosing the benefits by design.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

patrikG wrote:If there was a degree of consistency in their use of design patterns, plus a seperation of logic and view, it would be fantastic. Mambo's DB-class for example has some nice ideas & they seperate content and view, but not logic and view. And that's what I find most taxing: their constant mix of logic and view. Thus, while they are, by name, using "templates", they are not implementing the concept and are loosing the benefits by design.
Like I said some may find it obscene. However, I think the Mambo example maybe useful to jaymoore_299 because he does not seem to need anything more complex than good ol' PHP scriptlets.
Post Reply