Jump to content

Archived

This topic is now archived and is closed to further replies.

joshman13

php template engine

Recommended Posts

hello everyone,
i am looking at building a lightweight template engine for some of my
scripts that i am using. i have looked into several different ones, and
although many have great features, none have exactly what i am looking
for. the main thing i haven't liked is that most of them use
{placeholder} style tags, which creates unnecessary overhead, because
php itself is a template language, so why create a wrapper for
something that already does the job?

for most of the pure php template classes, this is what i've seen for
the most part:

: assign variables that replace content
: start an output buffer
: include the template file
: store the rendered content of the template file in a varable
: clear the output buffer
: return the rendered content

i really like this format just because it allows sub-templates in a
main file. for instance, i can have a template file for the complete
shell, but then have another file to include everytime i want a table,
or a menu, or anything modular like that.

i was thinking about this though, and basically the entire page is
stored in a variable before the output is ever sent to the screen. are
there any drawbacks to doing it this way? what about speed and memory?
are there better ways to go about it?

Share this post


Link to post
Share on other sites
Template engines such as smarty cache the pages as pure html. So the page is only drawn the first time, or if it changes.

Share this post


Link to post
Share on other sites
try mustache for PHP

https://github.com/bobthecow/mustache.php

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.