Skip to content

Instantly share code, notes, and snippets.

@battlejj
Last active December 20, 2015 02:09
Show Gist options
  • Save battlejj/6054619 to your computer and use it in GitHub Desktop.
Save battlejj/6054619 to your computer and use it in GitHub Desktop.
fs = require 'fs'
hogan = require 'hogan.js'
routes = {}
templates = {}
templates =
playout: hogan.compile(fs.readFileSync('./views/partial_layout.hjs').toString())
pindex: hogan.compile(fs.readFileSync('./views/partial_index.hjs').toString())
ptweet: hogan.compile(fs.readFileSync('./views/partial_tweet.hjs').toString())
routes.partial = (req, res)->
page =
title: 'Express'
someVar: 'test'
anArray: [{name:'item1'}, {name:'item2'}]
tweets: [
author: "complexcarb"
tweet: "lolwut is going on here"
,
author: "complexcarb"
tweet: "oh boy here we go."
]
partials =
template: templates.pindex
tweet: templates.ptweet
rendered = templates.playout.render(page, partials)
res.send(rendered)
{{> tweet }}
<h1>{{ title }}</h1>
<p>Welcome to {{ title }}</p>
{{ someVar }}
<ul>
{{# anArray }}
<li>{{ name }}</li>
{{/ anArray }}
</ul>
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
Hey
{{> template }}
</body>
</html>
<ul>
{{# tweets }}
<li>@{{ author }} - {{ tweet }}</li>
{{/ tweets }}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment