views:

79

answers:

3

A colleague made a small module to retrieve twitter search results based on user configurable search terms and display them in a block.

He is doing the searching with javascript to keep that traffic on the client side, something like: $.getJSON('http://search.twitter.com' etc.. Then when the json results are returned inserting them into the block, wrapping the returned data in html and appending it to the block.

Is there a way that this could be made themeable from the javascript layer? Without it being passed back into drupal and losing the bandwidth etc advantage of having it sit client side?

+1  A: 

Use semantic HTML and just style the generated HTML with CSS.

Ryan McGeary
Yeah, that's _pretty much_ what is happening now, and may be the best solution. I think I am also interested in a general solution that could be applied to more complicated examples where that may not cover all bases.
Andrew
The general solution is to use general semantic HTML that models, say "remote messages."
Ryan McGeary
A: 

You could theme it entirely with CSS.

rjmunro
I think you mix up styling with theming. Theming in Drupal denotes the generation of markup from some arbitrary form of data (e.g. json or XML in this case). So you need to first *theme* the data into markup, in order to *style* it via CSS afterwards.
Henrik Opel
+5  A: 

As of Drupal 6, modules providing/fetching dynamic content by means of javascript are supposed to turn that into HTML by calling Drupal.theme('function_name', ...) from the Drupal js namespace. Modules can/should provide their own js theming functions (or overrides) by adding them to the Drupal.theme.prototype namespace.

The mechanism is supposed to work similar to the standard theming mechanism, but is a bit insufficiently documented so far. See this entry in the module conversion guide, as well as the example towards the end of this post.

Henrik Opel
+1 - That is precisely the "drupal way" of doing things.
mac
+1 Nice, I didn't even know Drupal did that.
googletorp