As far as I can see there are two ways of building a html page: "inside" the language (I'll call it building for lack of a better name) or outside the language (using templates). Let me explain a bit what I mean by this before I jump to the questions.
Building
One way is to build the html page "inside" the language you are using, using preferably in-language constructs (not just by concatenating strings), and converting these constructs to html in one last step.
A really good example of this is Clojure's hiccup library, which uses the Clojure maps and vectors to represent the html. This allows one to use the full power of the language one's working in to manipulate these structures.
Templating
The second way is to write the html separately from the main program and use some kind of template DSL to insert logic into the templates. The hamlet package for Haskell is an example of this.
Now my question is: what are other advantages and disadvantages of both approaches?
I'd love to get more acquainted with these concepts so pointers to articles etc. are more than welcome. Also please inform me if there is another approach I didn't think of.
Summary of answers so far
Pro templating
- It's easier to separate the view from the rest of the code. The code will be easier to maintain and you avoid mixing business logic with the rest of your code.
- This approach generally is much more accessible to people with less technical skills.
Con templating
(none so far)
Pro building
- Functional languages, make it easy to write declarative code natively so a template language is not required.
- You can get all the power and flexibility of your programming language, and still get the benefits of a declarative syntax.
Con building
- Designers/clients are bad at your preferred logic language.
- It still boils down to hard-coding the page into codem just that it is not separate template code.
- Has more power, that could be used inappropriately. You have to take extra care
to separate view code and business logic. - In ideal cases it is faster though.