Jump to content

Archived

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

glenelkins

Template Engine - Test1

Recommended Posts

Class file attached.

Hi

I am writing a templating engine, mainly for people who want to integrate database values into HTML pages without much knowledge of PHP or MySql.

I have the basic class file finished and would like some feedback. I have not created the engine as of yet as programmers i think providing the class as is is enough!

Anyway, the way the system works:

GenerateTemplate($html_file)
This function you pass the HTML file you want to use as the template. You create your own custom tags in the html page to where you want the information displayed. For example, you may have the following in the HTML page: {header} and {body} ... or <%header%> and <%body%> these can be setup however you like.The template is then returned with $classobject->ReturnTemplate

SortTemplateTags($template,$tags,$tag_values)
This function you need to run after the GenerateTemplate one. $template is the information passed back from GenerateTemplate in the $classobject->ReturnTemplate variable

so for example

[code]
$template=$classobject->ReturnTemplate;
SortTemplateTags($template,$tags,$tag_values);
[/code]

You create your own tags (as per the html file), lets say for example you added the two tags {header} and {body} to the HTML file. You would create an array for your tags and tag values as such:

[code]
$tags = array("tags" => "{header}", "{body}");
$tag_values = array("tag_values" => "This Is A Test Header","This Is A Test Body!");
[/code]

You then simply pass these to SortTemplateTags and display the whole page template with included information as such:

[code]
SortTemplateTags($template,$tags,$tag_values);
echo $classobject->ReturnTemplate;
[/code]

Please give some feedback with any suggestions for additions and such. Class file attached.

Cheers

g


[attachment deleted by admin]

Share this post


Link to post
Share on other sites
without wanting to sound negative, all i can see is that its a class that replaces stuff with stuff which apart from replacing stuff serves little other use.
what i've always noticed with database data is generally there's always a need for more than one row, which is where loops come in. so until it has this sort of functionality, i'd probably give it a thumbs down for the time being, but having said that i'd be keep to see it when it's cranked up a few notches and does more.

Sure, it's simple to use - but with simplicity comes a lack of functionality.

It's possibly not helped by the fact that I have a bit of a dislike for most template engines in general anyway, as ultimately they require learning a whole new bunch of syntax to replace a perfectly good set (PHP). See here as my reasons stem from this: http://www.massassi.com/php/articles/template_engines/
Cheers
Mark

Share this post


Link to post
Share on other sites
Hi

Thanks!

Im not sure what you mean about the number of rows...the tags in the HTML can be replaced with any kind of data, so you take as much data from as many rows as you like into a variable and pass it into the array for construction into the tag...obviously there is a long way to go from here, I just wanted to make sure the class worked globally rather than just for me...which i have had before!

What kind of functionality would you be looking for in a template engine?

Share this post


Link to post
Share on other sites
Hi Glen

If you have 5 blog entries, all with a title and body, you need a loop to run through them. Sure, you can do the loop in the code that drives the engine, but this would be dragging alot of presentation code into where it should not be - ie, stuff for formatting headings, etc. if there was only one entry, sure - this could be done directly in the template. but how do you plan handling more than one result, and formatting it from the template and not from the main code?

For me, it's about nothing apart from ease of development. I'm possibly the most unorganised, forgetful person I know, and the thought of trawling through pages of PHP to sort out a new layout for my site doesnt really do it for me. I actually made my own template engine, based very heavily on the one in the link I sent you. here's what it does, so hence what i always look for:

1, filters. i dont use these lots, but i put the functionality in there. for example, I have a 'swearies' filter which will run through the page starring out swear words, and one that turns the page into not much more than basic text (ideal for use on PDA's/mobile browsers). and other weird, wonderful and otherwise useless ones.

2, gzip compression

3, caching

4, uses PHP as its native language for tags. see above link as well as phpSavant (www.phpsavant.com)

other than that, there's not much else i look for. as long as it does its job and is fast, thats it really.

Cheers
Mark

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.