From 371d66ba2a549bf24d35c785773998debcab6db3 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Fri, 1 Apr 2011 17:47:03 -0700 Subject: [PATCH] Added layout(path) helper to change the layout within a view. Closes #610 --- examples/layout-control/views/pages/alternate.ejs | 2 +- lib/view.js | 5 +++++ test/fixtures/layout-switch.jade | 2 +- test/fixtures/layouts/alternate.jade | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/layout-control/views/pages/alternate.ejs b/examples/layout-control/views/pages/alternate.ejs index 369492647e..88832038f4 100644 --- a/examples/layout-control/views/pages/alternate.ejs +++ b/examples/layout-control/views/pages/alternate.ejs @@ -1,2 +1,2 @@ -<% locals.layout = 'layouts/alternate' %> +<% layout('layouts/alternate') %>

Page

\ No newline at end of file diff --git a/lib/view.js b/lib/view.js index 6330bd19d6..4bb267c55a 100644 --- a/lib/view.js +++ b/lib/view.js @@ -346,6 +346,11 @@ res._render = function(view, opts, fn, parent, sub){ if (cacheViews) cache[orig.view] = view; } + // layout helper + options.layout = function(path){ + layout = path; + }; + // render var str = view.fn.call(options.scope, options); diff --git a/test/fixtures/layout-switch.jade b/test/fixtures/layout-switch.jade index e91efc3112..36e4654dea 100644 --- a/test/fixtures/layout-switch.jade +++ b/test/fixtures/layout-switch.jade @@ -1,2 +1,2 @@ -- locals.layout = 'layouts/alternate' +- layout('layouts/alternate') h1 My Page \ No newline at end of file diff --git a/test/fixtures/layouts/alternate.jade b/test/fixtures/layouts/alternate.jade index f9bace29f5..8dab2d342b 100644 --- a/test/fixtures/layouts/alternate.jade +++ b/test/fixtures/layouts/alternate.jade @@ -1 +1 @@ -#alternate= body \ No newline at end of file +#alternate!= body \ No newline at end of file