Jump to content


Photo

Template Engine - Test1


  • Please log in to reply
3 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 10 October 2006 - 04:16 PM

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

$template=$classobject->ReturnTemplate;
SortTemplateTags($template,$tags,$tag_values);

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:

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

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

SortTemplateTags($template,$tags,$tag_values);
echo $classobject->ReturnTemplate;

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

Cheers

g


[attachment deleted by admin]
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 10 October 2006 - 04:34 PM

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....mplate_engines/
Cheers
Mark
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 10 October 2006 - 04:42 PM

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?
http://thewebsolutionprovider.com - A Solution For Everything Web!

#4 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 10 October 2006 - 04:53 PM

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
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users