Forum Moderators: coopster

Message Too Old, No Replies

Templates

Best method

         

malcolmcroucher

12:15 pm on Dec 13, 2007 (gmt 0)

10+ Year Member



I have been looking at templates the last couple of days and there are a few ways to do a template:

1. includes
2. tags
3. Template application or premade templates
4. Content management system?
5. Widget?

What has been your experience with a specific method?

jatar_k

1:56 pm on Dec 13, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I have always rolled my own using includes.

When I have tested other methods for the same site against others you mentioned, it was either pure overkill or it was slower

gergoe

3:53 pm on Dec 13, 2007 (gmt 0)

10+ Year Member



In one of may latest project I created php classes, made a sort of framework for handling them (onload, onprehtml, gettitle, ...) and the result was quite good. The only problem is the overhead because of the complexity, whatever you want to do on one of the pages, you have to implement them as class methods (functions). If you wish I can send you some examples.

phnord

5:22 pm on Dec 13, 2007 (gmt 0)

10+ Year Member



Check out Smarty..for building tag libraries and templates in PHP, it doesn't get any better. I am in the midsts of a fairly large templating/custom tag project using PHP. Smarty works great at plugging into the current framework your are developing. However, Smarty is just like PHP. In the right hands it is very powerful, but in the wrong hands things can get extremely messy and convoluted.

topr8

6:10 pm on Dec 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>>I have always rolled my own using includes.

ditto here, means i don't have to learn another system

phnord

7:16 pm on Dec 13, 2007 (gmt 0)

10+ Year Member



Eh, the only thing to learn are the concepts of common web development methodologies like MVC (and other design patterns), abstraction, etc.

Which being in the web application development game you should already know anyways. ;)

Smarty is great, but if your application is tiny, then it's far too much overhead...as any templating system would be. Using includes and a templating engine are really two different things.

topr8

7:38 pm on Dec 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




i looked at smarty once and it seemed to me there was a whole smarty syntax to learn - of course i could be totally mistaken.
[of course it is well used and doubtless ideal for certain situations]

to answer the OP

personally i have always gone for home made templates with include files, this works best for me as it is simple, i would add that i only make simple websites, so perhaps if you are looking to do complicated things then it could be different

topr8

7:42 pm on Dec 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Which being in the web application development game you should already know anyways.

well, maybe, but it's horses for courses.

actually i'd never heard of MVC and it hasn't held me back yet, although as i say i only develop my own simple sites, the busiest of which only gets 250k uniques a week, so i'm small scale

phnord

7:58 pm on Dec 13, 2007 (gmt 0)

10+ Year Member



actually i'd never heard of MVC

Ruby on Rails? Django? Struts? CodeIgniter? CakePHP? All MVC frameworks. It's pretty much a staple of modern web application development. I'd suggest at least getting familiar with the concept. Of course there are always different ways to approach a problem, but MVC is too much of a standard design pattern that it's almost second nature for any serious developer. Especially when working with groups of developers. It's all about separation of logic, view and data. Unfortunately PHP is plagued by people that freely embed, hard-code everything and churn out spaghetti code making it a nightmare for the next developer who works on the system.

PHP actually has a lot of great implementations of MVC and it will really speed up your development time too.

[en.wikipedia.org...]
[en.wikipedia.org...]

Not singling anyone out on this post, but this is a rudimentary concept. Especially if you are looking to put out production quality code that other developers and designers will use.

phnord

8:15 pm on Dec 13, 2007 (gmt 0)

10+ Year Member



i looked at smarty once and it seemed to me there was a whole smarty syntax to learn - of course i could be totally mistaken.

Yes this is true, but you don't have to use the Smarty syntax. In fact you can create your own. For instance I can create my own tags that perform all logic behind the scenes and output data that designers can manipulate and 'decorate' using JS and CSS. Smarty also provides caching functionality that's a no-brainer to implement.

A good example is Textpattern, if you have ever used that. They have a complete tag/template engine. You can use Smarty to do the same thing.

If you have ever created a tag library for use in JSP pages, it's also similar.

But again, as everyone has stated...you just need to evaluate your needs. If you really need a template engine then don't shy away from learning Smarty or one of the others (there are lots for PHP). It'll benefit you down the road anyways.

whoisgregg

10:45 pm on Dec 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I read an article about MVC once. I think the folks who came up with MVC also probably eat off those plates with little dividers to keep their food from touching. ;)

Jokes aside, there is value in keeping your work as lean as possible. I have sites where I write a header.php and footer.php, sites where I write a template class, and other sites with a system that somewhat resembles MVC. Most of the time I go for the simplest approach that meets that projects needs. ::shrug::

jatar_k

2:19 pm on Dec 15, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> Most of the time I go for the simplest approach that meets that projects needs.

that's the best approach

each project is different, there is no one size fits all, whatever is the fastest and most useful.

malcolmcroucher

5:48 pm on Dec 15, 2007 (gmt 0)

10+ Year Member



If I were to add a shopping basket on , could i use includes?

I have installed smarty but it looks easier just to write your own .