views:

118

answers:

3

I have a server-side web service that serves to multiple clients. Clients include web browsers, iPhone, BlackBerry, Android etc. My question is, I need to be able to generate dynamic content for views to these clients. Be it a full blown HTML template, an HTML snippet, JSON, XML, etc. Depending on the user-agent of the requesting client, a different "view" template gets generated and spat out by the web server.

My question is, are there any elegant "view" frameworks or styles out there to adapt that simplify managing all of these snippets/fragments/full templates into some orderly fashion? I've been looking for an elegant way to manage this myriad of client handling, with straight forward maintenance and a simple hand off procedure to User Interface developers.

A: 

First of all you should not return HTML by a webservice. IMHO a webservice should return generic/client independent form. I would suggest to use a simple ASPX web page that gets a bunch of XSL Layout transformations for some clients.

Make it customizable and you will not have to touch the code for a long time, even if new clients come along or your visualization changes.

MrFox
Html is a perfectly valid media-type to return from a REST interface. Microformats are an excellent example of using Html to provide machine readable information.
Darrel Miller
Darrel: You might be right, if you just server browsers. But the question states multiple clients - among them browsers. XML is an client and platform indipendent format for just these purposes. No need to force the other clients to use a browser-client friendly format for data. (Altough it's possible. But that's not the point.) There IS sence in XML and XSLT.
MrFox
+1  A: 

What you need is a clear separation between model and presentation. If you write a number of generic components that pull data out in a presentation-agnostic way (the model), you can then have a number of adapters, that render the output for each specific target (The views). There are frameworks around that tie all this up in one big package; They are usually labelled as MVC-frameworks. But you don't really need this, if it's not to your taste. For most kinds of output, you can use a template engine to help you write the views. For stuff that is more data - less presentation - such as JSON or XML and general output that is for machine consumption, you would probably use something else to generate the output though.

troelskn
I like Codeigniter and CakePHP. MVC is the way to go.
Abinadi
A: 

I think your looking for a template engine. I have been using Smarty for quite a while and really like it. It creates a separation between the logic and the design of the pages. All you would need to do is load the template file for the user agent that made the request. The rest of the logic would remain the same.

http://www.smarty.net/

Kevin