Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/76295-solved-template-system/
Share on other sites

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.

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.

  • 2 weeks later...

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.