AUG
Template Technologies: Mix them in your app
The 10gen platform was recently written about in the German "Jaxenter" online magazine:
It's a nice writeup (as far as I can tell from the Yahoo! Babelfish! translation!) and kudos to the author, who I think did a good job - he downloaded the SDK and actually took it for a test drive.
One of the things that I appreciated was that he grokked the idea that you can mix template styles in the app (forgive the Babelfish translation...):
"An interesting realization, which one can gain from this simple example, is those that the different Template technologies can be mixed with one another."
He didn't elaborate further, but I think that this is an important aspect of our technology - the appserver supports the use multiple template technologies seamlessly and simultaneously in an application.
If you look at the "samplesite" demo app that comes with the SDK, you'll see the following [trivial] example of this in controller.jxp where the code calls three different templates and passes each data (template1, template2 and template3 in the templates directory of the application) to render into the output stream:
local.templates.template1({ theCount : data.count})
local.templates.template2({countThis : data.count})
local.templates.template3({ countThat : data.count})
Note that the variable name is changed to show that each template is independent.... What you don't need to worry about as a programmer here is that these three templates are actually of different types. "template1" is a djang10 template, "template2" is a jxp, and "template3" is 10gen html.
Briefly, the 10gen appserver supports:
- djang10 : this is a re-implementation of the great template system from the Django web application platform. We really like Django, and are re-implementing it as fast as we can, as accurately as we can.
- jxp : similar to the deservedly-maligned JSPs, where you mix markup and actual JavaScript in the same document
- html : another 10gen-invented template, it's like jxp with added enhancements for in-line data access via
$variable_name. It was the first templating system that we did (we wanted to make it easy to mix data into existing HTML) and if you are starting fresh, we suggest that you use djang10.
So why is this important? Well, I'd never advocate that one goes and starts building an application with multiple template styles out of the gate, but software re-use is important in keeping project construction and maintenance costs under control, and supporting multiple template styles as first class citizens for an application helps with this goal. This will make it easer to reuse app components, irrespective of the template style chosen by the author.
Note also that this part of our architecture allows for easy evolution and customization as this system is pluggable - you can easily implement other template styles, plug them into the appserver, and they can be first class templates as well. To see how this works, go look at
ed.appserver.templates.TemplateEngine.java
in the appserver. (Look in the nightly source download). I'm hoping someone contributes a support for my favorite template engine. ;)
Next time, I'll talk about mixed languages - how your app can use JavaScript and Ruby (and Python, even though Eliot doesn't want me to mention it as it's really not ready. But you can try it. Download the SDK...) code at the same time, in the same app.

Comments
Peter Svensson
I'm following this with interest. SSJS is the way forward (IMHO) and I've worked a bit with the Persevere SSJS framework from Kris Zyp (of Dojo Sitepen fame).
If you could use or leverage that into the 10gen platform, it would be awesome.
It's basically a REST server in JS with a _LOT_ of bells and whistles on top - and also full Dojo 1.2 compatibility, of course :)
Persevere does the following;
* Create, read, update, and delete access to persistent data through a standard JSON HTTP/REST web interface
* Dynamic object persistence - expando objects, arrays, and JavaScript functions can be stored, for extensive JavaScript persistence support
* Remote execution of JavaScript methods on the server through JSON-RPC for a consistent client/server language platform
* Flexible and fast indexed query capability through JSONQuery/JSONPath
* Comet-based data monitoring capabilities through HTTP Channels with Bayeux transport plugin/negotiation support
* Data-centric capability-based object level security with user management, Persevere is designed to be accessed securely through Ajax with public-facing sites
* Comprehensive referencing capabilities using JSON referencing, including circular, multiple, lazy, non-lazy, cross-data source, and cross-site referencing for a wide variety of object structures
* Data integrity and validation through JSON Schema
* Class-based data hierarchy - typed objects can have methods, inheritance, class-based querying
* Pluggable data source architectures - SQL tables, XML files, remote web services can be used as data stores
* Service discovery through Service Mapping Description
http://persevere.sitepen.com/
Cheers,
PS
geir
Looks interesting - we'll certainly take a look.
Thanks for the pointer.
OTOH, why not contribute it to the server? :)
-geir