javascript (and jquery) templating

I just put up some code for doing templating with javascript(and jquery). Either on the server side or on the client side. If you open the html in your browser, it runs on the client side. If you first process it server side... then it runs server side(but not on the client side).

This is a followup from you are using the wrong templating language - as a proof of concept.

Why is this useful?

  • No need for a server to process the templates. Either process them server side or client side.
  • Data can be stored in a json file. No need for a database for testing. Just create json files in a text file.
  • Can reuse knowledge of javascript libraries (like jquery), rather than learning one of 798394 different templating languages.
  • Can keep one html file which front end web developers can edit without them needing a new template file.
  • Can use jquery plugins on server side too(validation, etc).

Seems to work ok so far... but it still needs a lot of polish before it'll be useful. If it works out ok, I'll try it out on some real projects (where the main server side language is python).


Anonymous said…
Impressive work, haven't checked out the code yet (but will clone it later)... Q: How does the server-side process the templates ? What do you need server-side (per say) ?
illume said…

it currently uses the nodejs server - which uses the v8 javascript implementation.

It should be easy enough to use various other javascript implementations though.
Anonymous said…
Wow quick response :) You must be checking blog comments every few mins or have instant notifications!

Yeah I was wondering about that... nodejs seems to be picking up quite a bit of popularity (I guess because of the same language server-side and client-side aspect). I was going to try out your code with my python web framework circuits.web (see my bb projects).

illume said…
hi ya,

yeah I get an email when someone comments... so I can delete spam and read comments in my email.

Note the code is a bit ugly, and buggy at the moment... so not for production but still fun to play with :)

If you have any questions about it or nodejs etc please let me know. I tried to add a little documentation in there to make it easier to play with.

Now to try and clean it up enough to use in a real project...


Popular posts from this blog

Is PostgreSQL good enough?

Experiments with new low latency PyPy garbage collector in a thread.

🐱‍🏍 — the first pygame 2 community game. Starting now! Are you in?