stuffradio Posted November 6, 2007 Share Posted November 6, 2007 I just need to design a really simple template system. What sorts of things do i need to use when making a templating system. I will be using Classes of course. I already know about simple things like require_once and includes... but I want it like Folders: Themes->Theme Name->index file Classes->Template.class(or something)->contains code for the templates What types of methods in PHP should I use to accomplish this? It's partly for my previous post I made in this forum and partly for educational purpose and practice with classes. Any suggestions? Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted November 7, 2007 Share Posted November 7, 2007 this might be a good start for something very simple: http://www.massassi.com/php/articles/template_engines/ the one i built for myself was heavily based on the stuff there and works a treat. Quote Link to comment Share on other sites More sharing options...
stuffradio Posted November 12, 2007 Author Share Posted November 12, 2007 So... do you think I should basically copy what he has there, and change it to how I want? Or should I just learn the method that was used, and try and invent my own? Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted November 12, 2007 Share Posted November 12, 2007 either or. using what he has there will get you a decent (albeit basic) understanding of using things like that - try and put a mini site using it, for example - and you'll be able to better judge if it fits your requirements. but as it's quite simple, using it to write your own shouldn't be too tricky. my own, for example, is based on that with the addition of GZIP support, caching, loading templates from a database, etc - all of which is still quite lightweight but easily changed for each project i do and the requirements. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted November 12, 2007 Share Posted November 12, 2007 I have taken a look at that and it basically just use straight PHP and HTML. I never see the point of template engine because even in the template file you sometimes have to have some logic like if statements and what not(that is way they support them). I can easily have the logic on the top of the file and the html and echo statements on the bottom(you can even separate the two into 2 files). The only thing you don't get in the cached files which i don't see a big deal with it. Just my point of view, I just never have seen the point of a template system. Quote Link to comment Share on other sites More sharing options...
Evan69 Posted November 22, 2007 Share Posted November 22, 2007 foreach($this->vars as $k => $v) { $this->contents = str_replace("{" . $k . "}", $v, $this->contents); } thats a pretty simple way of replaces an array of tags: $this->vars (example: array("TITLE" => "Home Page", "BODY" => "Welcome...")) in the template file $this->contents. Quote Link to comment Share on other sites More sharing options...
stuffradio Posted November 22, 2007 Author Share Posted November 22, 2007 Interesting way of doing it Evan Nonetheless... this topic is solved I guess. Quote Link to comment 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.