From 6ecc389370b05a7e0f3225228b1e9c8f5272db4b Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Fri, 23 Oct 2015 02:02:26 +0100 Subject: [PATCH] Fix data merging & add pagination block param refs #5993 - Don't merge the result set with the existing template data. - If available, return `meta.pagination` as the second blockParam --- core/server/helpers/get.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/core/server/helpers/get.js b/core/server/helpers/get.js index affd733c02..df475202f4 100644 --- a/core/server/helpers/get.js +++ b/core/server/helpers/get.js @@ -83,14 +83,24 @@ get = function get(context, options) { apiOptions = parseOptions(this, apiOptions); return apiMethod(apiOptions).then(function success(result) { - result = _.merge(self, result); + var blockParams; + + // If no result is found, call the inverse or `{{else}}` function if (_.isEmpty(result[context])) { return options.inverse(self, {data: data}); } + // block params allows the theme developer to name the data using something like + // `{{#get "posts" as |result pagination|}}` + blockParams = [result[context]]; + if (result.meta && result.meta.pagination) { + blockParams.push(result.meta.pagination); + } + + // Call the main template function return options.fn(result, { data: data, - blockParams: [result[context]] + blockParams: blockParams }); }).catch(function error(err) { data.error = err.message;