jQuery + jQuery.Template: getting the result out as text

jQuery + jQuery.Template: getting the result out as text

Hi, I'm working on a server-side templating solution using jQuery + jQuery.Template on NodeJS -- and have it 90% working after a little 'experimenting' with getting an adequate server-side DOM/BOM configured. I just have a couple of problems I'm hoping I can get some advice on...

First: how to I convert the result of $.tmpl(template, data) to a string representation of the resulting HTML? Currently I've hacked it as follows:

  1. var result = $.tmp(template, data);
  2. var html = $('<div>').append(result).html();

but it seems like I shouldn't need the overhead of creating the additional DOM node there... is there a way to avoid it? result.html() doesn't seem to work (at least, not if the template contains more than one root element).

The second problem is probably related: I need to be able to represent complete HTML documents as templates, which is working *except* that the <!doctype ...> is getting stripped... is that purely a result of the append-to-div hack?