Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4361ce683f
Fetching contributors…

Cannot retrieve contributors at this time

86 lines (79 sloc) 2.129 kb
<!doctype html>
<title>Kernel Template Language Test in Browser</title>
<script src="kernel.js"></script>
<script name="tasks" type="text/x-kernel-template">
<h1>Tasks for {name}</h1>
<li>{task} ({{index + 1}}/{tasks.length})</li>
<p>Congratulations! Your tasks are all done</p>
{partial("footer", this)}
<script name="footer" type="text/x-kernel-template">
<footer>This was tasks for {name}</footer>
<div id="target"></div>
"use strict"
var helpers = {
partial: function (name, locals, callback) {
Kernel(name, function (err, template) {
if (err) {return callback(err); }
template(locals, callback);
if: function (condition, block, callback) {
if (condition) return block({}, callback);
callback(null, "");
unless: function (condition, block, callback) {
if (!condition) return block({}, callback);
callback(null, "");
loop: function (array, block, callback) {
var left = array.length;
if (!left) return callback(null, "");
var parts = new Array(left);
var done = false;
array.forEach(function (value, index) {
value.index = index;
block(value, function (err, result) {
parts[index] = result;
if (done || --left) return;
done = true;
if (err) return callback(err);
callback(null, parts.join(""));
var site = Object.create(helpers); = "Tim Caswell";
Kernel("tasks", function (err, template) {
if (err) throw err;
var data = Object.create(site);
data.tasks = [
{task: "Program Awesome Code"},
{task: "Play with Kids"},
{task: "Answer Emails"},
{task: "Write Blog Post"},
template(data, function (err, result) {
if (err) throw err;
if (err) throw err;
document.getElementById('target').innerHTML = result;
Jump to Line
Something went wrong with that request. Please try again.