glenelkins Posted October 10, 2006 Share Posted October 10, 2006 Class file attached.HiI 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->ReturnTemplateSortTemplateTags($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.Cheersg[attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/23566-template-engine-test1/ Share on other sites More sharing options...
redbullmarky Posted October 10, 2006 Share Posted October 10, 2006 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/CheersMark Quote Link to comment https://forums.phpfreaks.com/topic/23566-template-engine-test1/#findComment-106969 Share on other sites More sharing options...
glenelkins Posted October 10, 2006 Author Share Posted October 10, 2006 HiThanks!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? Quote Link to comment https://forums.phpfreaks.com/topic/23566-template-engine-test1/#findComment-106978 Share on other sites More sharing options...
redbullmarky Posted October 10, 2006 Share Posted October 10, 2006 Hi GlenIf 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 compression3, caching4, 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.CheersMark Quote Link to comment https://forums.phpfreaks.com/topic/23566-template-engine-test1/#findComment-106982 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.