Separate design from codes

Hello guys/gals,

Can anyone point me in the right direction. I want to make small CMS or let’s call it developing a new website but I want to separate code from design completely.

How do you guys/gals go about this?

Anything in this regard is great. I will read.

There are no gals on this forum. They’re in the kitchen making us programmer men some sandwiches and ironing our shirts. Thanks be to zeus, this forum is still untouched by any of those crazy postmodern feminist ideals.

And since you brought it up, you ought to come to one of our naked men in the woods retreats, where we all get naked and throw each other up in the air using rugged outdoorsy quilts. And the best part is: no women allowed! That’s right. A real manly getaway.

But seriously, google “passive view”. The basic idea is that you have a script that sets up a bunch of variables, picks a template, and fills it in. Not very complicated obviously, but it takes some discipline to pull off. It’s just too easy to put stuff into a template. In fact, a lot of people don’t know this, but the last temptation of Christ was actually putting SQL queries into a template.

Beyond that, you’ve been rather general in your description of the project. You’ll probably get more helpful input if you provide more specifics.

Cuberoots weird fantasies aside, it sounds like you need a basic separation between controller code and template. You need to decide on a template engine, and unfortunately there is no de-facto standard choice. The closest you’ll get to a standard is probably Smarty - Loved by some, and loathed by many more.

Like kyberfabrikken said I would reccomend using Smarty, or perhaps creating your own templating system to accomodate what you want.

First of all, cuberoot wtf are you smoking and can I have some :D…

Second, EEEtc… separating code from design is a rather vague description for someone looking for help. I doubt you bothered to search the forums for this topic. I remember reading posts about this very issue over 2 years. Just search and sift through what information is already on the forums and I’m sure you’ll find several answer’s to satisfy your fancy.

imho smarty adds too much baggage, css is just as good if not better

CSS can’t separate the code and content layers, it can only separate the content and appearance layers.

While there are different languages for the client side layers - behaviour, appearance, content - there are not separate languages for all the further layers server side - content, code, database etc. - and so you need to make a conscious decision to actually divide up the code into separate modules to represent those layers if you want to make maintaining everything easier as the whole thing grows to contain huge numbers of pages that need to use common coding layers etc.

Read this: http://massassi.com/php/articles/template_engines/

like others, i feel that a ‘template engine’ is overkill. PHP is essentially a template engine, so why make another template engine on top of an existing template engine? BUT! for the sake of learning how to separate business logic from presentation logic, i’m going to suggest using a template engine (i.e. smarty). using an existing template engine and adhering to conventions will help you better understand what constitutes presentation logic and what doesn’t. once you can make this distinction, you will not only be able to drop your redundant template engine for plain PHP, but you’ll also be a much better programmer.

good luck.

Hi EEEtc, I could be way off beam here but it sounds like you’re talking about an MVC (Model View Controller) pattern.

It works like this. Your web request comes in and gets routed to a controller written in PHP or whatever. The controller goes to the database and pulls everything it needs creating a model, which might be a hash or an array or a PHP object or whatever. Then the controller passes the model to a template View which renders the page.

It’s a nice clean way to do things because you get full separation between roles. You have your actions, your data and your display. It’s similar to the way we use Javascript, HTML and CSS in the front end to give us separation between roles.

You can swap out the view layer if you need to reskin the page or something, change to a different templating engine or just ship out XML or JSON for whatever reason.

Codeigniter is a good PHP framework, beyond that you could try Rails3 or Django. Hope this answers your question and I didn’t misunderstand you too wildly :slight_smile:

goldfidget - this thread is more than 2 years old. I’m thinking that the original author probably made his mind up by now.

Oh my, oops. (: