Skip to content

Instantly share code, notes, and snippets.

@MrJaba
Created July 30, 2010 12:02
Show Gist options
  • Save MrJaba/500385 to your computer and use it in GitHub Desktop.
Save MrJaba/500385 to your computer and use it in GitHub Desktop.
var sys = require('sys'),
http = require('http'),
require('./mustache'); //require with ./ as it's in local directory
//Set up a template to render HTML with {{title}} is a tag which gets replaced with content
//{{{content}}} is another tag which gets replaced. The triple moustache (curly brace) means don't escape HTML
var html_template = "<html><head><title>{{title}}</title></head><body>{{{content}}}</body></html>";
//Setup a basic form so we can post some data to the node server \'s are there to do multiline strings in Javascript
//Later on this can be hidden away in another file to make the code look prettier
var form = function() {return "<div id='container'> \
<form method='post' action='/addTime'> \
<ul> \
<li> \
<label for='element_1'></label> \
<div> <input name='activity' type='text' value=''/> </div> \
</li> \
<li> \
<input type='submit' name='submit' value='Submit'/> \
</li> \
</ul> \
</form> \
</div>"};
//This is the object that will provide the data to the html_template above using Mustache
var index_view = { title : "Time", content : form };
//The Mustache.to_html method creates the template which gets rendered to the client
Mustache.to_html(html_template, index_view)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment