General Question

tantaikooi's avatar

Do you seperate HTML from code?

Asked by tantaikooi (122points) February 5th, 2008

Is this a painful thing to do?...any cool and easy idea?

Observing members: 0 Composing members: 0

14 Answers

Evert's avatar

CODE, or simply code? (abbrev/acronym, like HTML?)
I definitely separate them, and once I got my head ‘round it (pretty quickly), I found thing pretty easy and much more readable. It’ll depend, though what you are using currently? In particular, what kind of “CODE” are you using (or planning to use).

Perchik's avatar

What code are you talking about? javascript perhaps?

Html IS code…which is why I’m slightly confused

tantaikooi's avatar

sorry, i mean server-side programming code.

Evert's avatar

All the more for server side code, although I’ve found it more difficult with PHP than with eg Python; hence my question on what kind/type of code (language). But makes maintenance and readability so much nicer (after all, you put your javascript and css in separate files as well, don’t you?).

adrianscott's avatar

Some kind of system architecture, such as MVC, is a really good way to promote code re-use and simple code maintenance.

I try to do as much as I can to separate out my “business logic” from the “display” code, without going overboard of course.

phoenyx's avatar

minor nitpick: HTML is markup, not code.

cwilbur's avatar

Of course I separate the code from the HTML. Ideally, there are three types of files in a web project: HTML template files, which don’t have any logic more complicated than a for loop to display a table of results or an if/then statement to determine whether something should be displayed; code files, which have the actual logic in them (and which are likely divided into Javascript files for client-side work, pulled in with unobtrusive Javascript techniques, and whatever server-side language I’m using); and CSS files, which determine how things are styled and displayed.

Vincentt's avatar

I don’t, really. I do use MVC, but for the view, I prefer to use plain PHP rather than some obscure template language to achieve the same thing. I do try to keep it simple though.
Of course, this is much easier for me as I tend to create “templates” just in CSS, if at all. By use of MVC, it is still easy for me to update the HTML, but I have no need to have designers edit it, which might not be the case for larger projects.

krypin's avatar

smarty template engine. Once you start using it you can’t live without it

tantaikooi's avatar

I never used any template b4, wonder how easy will it be..for me it seems like need to learn another language…

phoenyx's avatar

The smarty template engine is the only template system I’ve used that I can’t stand.

stanley00's avatar

For server-side code (PHP, Ruby, etc.), I don’t separate the two. I use the code to generate the HTML. To keep it organized, sometimes I use an MVC framework (as above).

For client-side code (JavaScript), it becomes more important. For that I use JQuery and well-considered class names.

xyzzy's avatar

I have to agree with Vincentt. Everyone forgets that PHP IS a templating engine (that has grown up into a full programming language). I’ve never understood the logic of implementing another template engine on top of it.

marcospereira's avatar

Yes. I do that.

Like @stanley00 and others, I use JQuery to avoid intrusive JavaScript code. This technique is called unobtrusive javascript.

About server side code, I use MVC pattern too.

Kind Regards

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther